{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Setup"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "collapsed": false,
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "%matplotlib inline\n",
    "# Plot everything as SVG\n",
    "%config InlineBackend.figure_formats=['svg']\n",
    "\n",
    "\n",
    "import math\n",
    "import matplotlib.pyplot as plt\n",
    "from functools import partial\n",
    "np.random.seed(1)\n",
    "\n",
    "# for fixing matplotlib's svg clipping\n",
    "from lxml import etree\n",
    "\n",
    "# Config styling\n",
    "#palette = [\"#9b59b6\", \"#3498db\", \"#95a5a6\", \"#e74c3c\", \"#34495e\", \"#2ecc71\"]\n",
    "palette = ['#386DF9', '#FFDC52', '#FF1614', '#62F591', '#AA22FF', '#34495E']\n",
    "muted = '#dcdce6'\n",
    "\n",
    "# A sans-serif math font fits better, but the spacing for `stixsans` is weird\n",
    "plt.rcParams['mathtext.fontset'] = 'stixsans'\n",
    "plt.rcParams.update({'font.size': 18})\n",
    "\n",
    "def save(name):\n",
    "    fname = '../notes/assets/{}.svg'.format(name)\n",
    "    plt.savefig(fname)\n",
    "    \n",
    "    # edit the resulting svg to fix clipping issues\n",
    "    # see <https://github.com/matplotlib/matplotlib/issues/2277>\n",
    "    with open(fname, 'r') as f:\n",
    "        raw = f.read()\n",
    "    svg = etree.fromstring(raw.encode('utf-8'))\n",
    "    \n",
    "    # the last <defs> tag contains the clipping info\n",
    "    defs = [c for c in svg.getchildren() if c.tag == '{http://www.w3.org/2000/svg}defs'][-1]\n",
    "    \n",
    "    # move it to the beginning\n",
    "    svg.insert(0, defs)\n",
    "    \n",
    "    # re-write the svg\n",
    "    with open(fname, 'w') as f:\n",
    "        raw = etree.tostring(svg, pretty_print=True).decode('utf-8')\n",
    "        f.write(raw)\n",
    "        \n",
    "        \n",
    "def save_png(name):\n",
    "    fname = '../notes/assets/{}.png'.format(name)\n",
    "    plt.savefig(fname, dpi=300)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "# http://daft-pgm.org/api/\n",
    "import daft\n",
    "\n",
    "def add_node(pgm, name, body, x, y, **kwargs):\n",
    "    # for consistent scale\n",
    "    pgm.add_node(daft.Node(name, body, x, y, scale=1.2, **kwargs))\n",
    "    \n",
    "def add_edge(pgm, frm, to, label=''):\n",
    "    # for consistent scale\n",
    "    if pgm._ctx.directed:\n",
    "        # ref: <http://matplotlib.org/api/patches_api.html#matplotlib.patches.FancyArrow>\n",
    "        pgm.add_edge(frm, to, head_length=0.1, head_width=0.15, fill=False, label=label)\n",
    "    else:\n",
    "        pgm.add_edge(frm, to)\n",
    "        \n",
    "def add_edges(pgm, pairs):\n",
    "    for pair in pairs:\n",
    "        if len(pair) == 3:\n",
    "            frm, to, label = pair\n",
    "            add_edge(pgm, frm, to, label=label)\n",
    "        else:\n",
    "            frm, to = pair\n",
    "            add_edge(pgm, frm, to)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "image/svg+xml": [
       "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"no\"?>\n",
       "<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\n",
       "  \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n",
       "<!-- Created with matplotlib (http://matplotlib.org/) -->\n",
       "<svg height=\"184pt\" version=\"1.1\" viewBox=\"0 0 184 184\" width=\"184pt\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n",
       " <defs>\n",
       "  <style type=\"text/css\">\n",
       "*{stroke-linecap:butt;stroke-linejoin:round;stroke-miterlimit:100000;}\n",
       "  </style>\n",
       " </defs>\n",
       " <g id=\"figure_1\">\n",
       "  <g id=\"patch_1\">\n",
       "   <path d=\"M 0 184.47874 \n",
       "L 184.47874 184.47874 \n",
       "L 184.47874 0 \n",
       "L 0 0 \n",
       "L 0 184.47874 \n",
       "z\n",
       "\" style=\"fill:none;\"/>\n",
       "  </g>\n",
       "  <g id=\"axes_1\">\n",
       "   <g id=\"patch_2\">\n",
       "    <path clip-path=\"url(#p7110b7bb3d)\" d=\"M 75.231496 63.892913 \n",
       "L 72.39685 66.018898 \n",
       "L 72.39685 63.892913 \n",
       "L 52.554331 63.892913 \n",
       "L 52.554331 63.892913 \n",
       "L 72.39685 63.892913 \n",
       "L 72.39685 61.766929 \n",
       "L 75.231496 63.892913 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_3\">\n",
       "    <path clip-path=\"url(#p7110b7bb3d)\" d=\"M 35.546457 103.577953 \n",
       "L 33.420472 100.743307 \n",
       "L 35.546457 100.743307 \n",
       "L 35.546457 80.900787 \n",
       "L 35.546457 80.900787 \n",
       "L 35.546457 100.743307 \n",
       "L 37.672441 100.743307 \n",
       "L 35.546457 103.577953 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_4\">\n",
       "    <path clip-path=\"url(#p7110b7bb3d)\" d=\"M 52.554331 120.585827 \n",
       "L 55.388976 118.459843 \n",
       "L 55.388976 120.585827 \n",
       "L 75.231496 120.585827 \n",
       "L 75.231496 120.585827 \n",
       "L 55.388976 120.585827 \n",
       "L 55.388976 122.711811 \n",
       "L 52.554331 120.585827 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_5\">\n",
       "    <path clip-path=\"url(#p7110b7bb3d)\" d=\"M 80.212987 108.559444 \n",
       "L 76.705292 108.058344 \n",
       "L 78.20859 106.555047 \n",
       "L 47.57284 75.919296 \n",
       "L 47.57284 75.919296 \n",
       "L 78.20859 106.555047 \n",
       "L 79.711888 105.051749 \n",
       "L 80.212987 108.559444 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_6\">\n",
       "    <path clip-path=\"url(#p7110b7bb3d)\" d=\"M 123.171052 101.253525 \n",
       "L 121.894047 104.558716 \n",
       "L 120.767278 102.755884 \n",
       "L 106.662018 111.571672 \n",
       "L 106.662018 111.571672 \n",
       "L 120.767278 102.755884 \n",
       "L 119.640508 100.953053 \n",
       "L 123.171052 101.253525 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_7\">\n",
       "    <path clip-path=\"url(#p7110b7bb3d)\" d=\"M 92.23937 103.577953 \n",
       "L 90.113386 100.743307 \n",
       "L 92.23937 100.743307 \n",
       "L 92.23937 80.900787 \n",
       "L 92.23937 80.900787 \n",
       "L 92.23937 100.743307 \n",
       "L 94.365354 100.743307 \n",
       "L 92.23937 103.577953 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_8\">\n",
       "    <path clip-path=\"url(#p7110b7bb3d)\" d=\"M 47.57284 108.559444 \n",
       "L 48.073939 105.051749 \n",
       "L 49.577237 106.555047 \n",
       "L 80.212987 75.919296 \n",
       "L 80.212987 75.919296 \n",
       "L 49.577237 106.555047 \n",
       "L 51.080535 108.058344 \n",
       "L 47.57284 108.559444 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_9\">\n",
       "    <path clip-path=\"url(#p7110b7bb3d)\" d=\"M 106.662018 72.907069 \n",
       "L 110.192563 72.606597 \n",
       "L 109.065793 74.409428 \n",
       "L 123.171052 83.225215 \n",
       "L 123.171052 83.225215 \n",
       "L 109.065793 74.409428 \n",
       "L 107.939024 76.212259 \n",
       "L 106.662018 72.907069 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_10\">\n",
       "    <path clip-path=\"url(#p7110b7bb3d)\" d=\"M 35.546457 80.900787 \n",
       "C 40.056998 80.900787 44.383406 79.108731 47.57284 75.919296 \n",
       "C 50.762274 72.729862 52.554331 68.403454 52.554331 63.892913 \n",
       "C 52.554331 59.382372 50.762274 55.055964 47.57284 51.86653 \n",
       "C 44.383406 48.677096 40.056998 46.885039 35.546457 46.885039 \n",
       "C 31.035916 46.885039 26.709508 48.677096 23.520074 51.86653 \n",
       "C 20.33064 55.055964 18.538583 59.382372 18.538583 63.892913 \n",
       "C 18.538583 68.403454 20.33064 72.729862 23.520074 75.919296 \n",
       "C 26.709508 79.108731 31.035916 80.900787 35.546457 80.900787 \n",
       "L 35.546457 80.900787 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_11\">\n",
       "    <path clip-path=\"url(#p7110b7bb3d)\" d=\"M 92.23937 137.593701 \n",
       "C 96.749911 137.593701 101.076319 135.801644 104.265753 132.61221 \n",
       "C 107.455187 129.422776 109.247244 125.096368 109.247244 120.585827 \n",
       "C 109.247244 116.075286 107.455187 111.748878 104.265753 108.559444 \n",
       "C 101.076319 105.37001 96.749911 103.577953 92.23937 103.577953 \n",
       "C 87.728829 103.577953 83.402421 105.37001 80.212987 108.559444 \n",
       "C 77.023553 111.748878 75.231496 116.075286 75.231496 120.585827 \n",
       "C 75.231496 125.096368 77.023553 129.422776 80.212987 132.61221 \n",
       "C 83.402421 135.801644 87.728829 137.593701 92.23937 137.593701 \n",
       "L 92.23937 137.593701 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_12\">\n",
       "    <path clip-path=\"url(#p7110b7bb3d)\" d=\"M 92.23937 80.900787 \n",
       "C 96.749911 80.900787 101.076319 79.108731 104.265753 75.919296 \n",
       "C 107.455187 72.729862 109.247244 68.403454 109.247244 63.892913 \n",
       "C 109.247244 59.382372 107.455187 55.055964 104.265753 51.86653 \n",
       "C 101.076319 48.677096 96.749911 46.885039 92.23937 46.885039 \n",
       "C 87.728829 46.885039 83.402421 48.677096 80.212987 51.86653 \n",
       "C 77.023553 55.055964 75.231496 59.382372 75.231496 63.892913 \n",
       "C 75.231496 68.403454 77.023553 72.729862 80.212987 75.919296 \n",
       "C 83.402421 79.108731 87.728829 80.900787 92.23937 80.900787 \n",
       "L 92.23937 80.900787 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_13\">\n",
       "    <path clip-path=\"url(#p7110b7bb3d)\" d=\"M 137.593701 109.247244 \n",
       "C 142.104242 109.247244 146.43065 107.455187 149.620084 104.265753 \n",
       "C 152.809518 101.076319 154.601575 96.749911 154.601575 92.23937 \n",
       "C 154.601575 87.728829 152.809518 83.402421 149.620084 80.212987 \n",
       "C 146.43065 77.023553 142.104242 75.231496 137.593701 75.231496 \n",
       "C 133.08316 75.231496 128.756752 77.023553 125.567318 80.212987 \n",
       "C 122.377884 83.402421 120.585827 87.728829 120.585827 92.23937 \n",
       "C 120.585827 96.749911 122.377884 101.076319 125.567318 104.265753 \n",
       "C 128.756752 107.455187 133.08316 109.247244 137.593701 109.247244 \n",
       "L 137.593701 109.247244 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_14\">\n",
       "    <path clip-path=\"url(#p7110b7bb3d)\" d=\"M 35.546457 137.593701 \n",
       "C 40.056998 137.593701 44.383406 135.801644 47.57284 132.61221 \n",
       "C 50.762274 129.422776 52.554331 125.096368 52.554331 120.585827 \n",
       "C 52.554331 116.075286 50.762274 111.748878 47.57284 108.559444 \n",
       "C 44.383406 105.37001 40.056998 103.577953 35.546457 103.577953 \n",
       "C 31.035916 103.577953 26.709508 105.37001 23.520074 108.559444 \n",
       "C 20.33064 111.748878 18.538583 116.075286 18.538583 120.585827 \n",
       "C 18.538583 125.096368 20.33064 129.422776 23.520074 132.61221 \n",
       "C 26.709508 135.801644 31.035916 137.593701 35.546457 137.593701 \n",
       "L 35.546457 137.593701 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"matplotlib.axis_1\"/>\n",
       "   <g id=\"matplotlib.axis_2\"/>\n",
       "   <g id=\"text_1\">\n",
       "    <!-- A -->\n",
       "    <defs>\n",
       "     <path d=\"M 34.1875 63.1875 \n",
       "L 20.796875 26.90625 \n",
       "L 47.609375 26.90625 \n",
       "z\n",
       "M 28.609375 72.90625 \n",
       "L 39.796875 72.90625 \n",
       "L 67.578125 0 \n",
       "L 57.328125 0 \n",
       "L 50.6875 18.703125 \n",
       "L 17.828125 18.703125 \n",
       "L 11.1875 0 \n",
       "L 0.78125 0 \n",
       "z\n",
       "\" id=\"BitstreamVeraSans-Roman-41\"/>\n",
       "    </defs>\n",
       "    <g transform=\"translate(29.3898941929 68.8597883858)scale(0.18 -0.18)\">\n",
       "     <use xlink:href=\"#BitstreamVeraSans-Roman-41\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"text_2\">\n",
       "    <!-- C -->\n",
       "    <defs>\n",
       "     <path d=\"M 64.40625 67.28125 \n",
       "L 64.40625 56.890625 \n",
       "Q 59.421875 61.53125 53.78125 63.8125 \n",
       "Q 48.140625 66.109375 41.796875 66.109375 \n",
       "Q 29.296875 66.109375 22.65625 58.46875 \n",
       "Q 16.015625 50.828125 16.015625 36.375 \n",
       "Q 16.015625 21.96875 22.65625 14.328125 \n",
       "Q 29.296875 6.6875 41.796875 6.6875 \n",
       "Q 48.140625 6.6875 53.78125 8.984375 \n",
       "Q 59.421875 11.28125 64.40625 15.921875 \n",
       "L 64.40625 5.609375 \n",
       "Q 59.234375 2.09375 53.4375 0.328125 \n",
       "Q 47.65625 -1.421875 41.21875 -1.421875 \n",
       "Q 24.65625 -1.421875 15.125 8.703125 \n",
       "Q 5.609375 18.84375 5.609375 36.375 \n",
       "Q 5.609375 53.953125 15.125 64.078125 \n",
       "Q 24.65625 74.21875 41.21875 74.21875 \n",
       "Q 47.75 74.21875 53.53125 72.484375 \n",
       "Q 59.328125 70.75 64.40625 67.28125 \n",
       "\" id=\"BitstreamVeraSans-Roman-43\"/>\n",
       "    </defs>\n",
       "    <g transform=\"translate(85.9548388287 125.552701772)scale(0.18 -0.18)\">\n",
       "     <use xlink:href=\"#BitstreamVeraSans-Roman-43\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"text_3\">\n",
       "    <!-- B -->\n",
       "    <defs>\n",
       "     <path d=\"M 19.671875 34.8125 \n",
       "L 19.671875 8.109375 \n",
       "L 35.5 8.109375 \n",
       "Q 43.453125 8.109375 47.28125 11.40625 \n",
       "Q 51.125 14.703125 51.125 21.484375 \n",
       "Q 51.125 28.328125 47.28125 31.5625 \n",
       "Q 43.453125 34.8125 35.5 34.8125 \n",
       "z\n",
       "M 19.671875 64.796875 \n",
       "L 19.671875 42.828125 \n",
       "L 34.28125 42.828125 \n",
       "Q 41.5 42.828125 45.03125 45.53125 \n",
       "Q 48.578125 48.25 48.578125 53.8125 \n",
       "Q 48.578125 59.328125 45.03125 62.0625 \n",
       "Q 41.5 64.796875 34.28125 64.796875 \n",
       "z\n",
       "M 9.8125 72.90625 \n",
       "L 35.015625 72.90625 \n",
       "Q 46.296875 72.90625 52.390625 68.21875 \n",
       "Q 58.5 63.53125 58.5 54.890625 \n",
       "Q 58.5 48.1875 55.375 44.234375 \n",
       "Q 52.25 40.28125 46.1875 39.3125 \n",
       "Q 53.46875 37.75 57.5 32.78125 \n",
       "Q 61.53125 27.828125 61.53125 20.40625 \n",
       "Q 61.53125 10.640625 54.890625 5.3125 \n",
       "Q 48.25 0 35.984375 0 \n",
       "L 9.8125 0 \n",
       "z\n",
       "\" id=\"BitstreamVeraSans-Roman-42\"/>\n",
       "    </defs>\n",
       "    <g transform=\"translate(86.0645263287 68.8597883858)scale(0.18 -0.18)\">\n",
       "     <use xlink:href=\"#BitstreamVeraSans-Roman-42\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"text_4\">\n",
       "    <!-- E -->\n",
       "    <defs>\n",
       "     <path d=\"M 9.8125 72.90625 \n",
       "L 55.90625 72.90625 \n",
       "L 55.90625 64.59375 \n",
       "L 19.671875 64.59375 \n",
       "L 19.671875 43.015625 \n",
       "L 54.390625 43.015625 \n",
       "L 54.390625 34.71875 \n",
       "L 19.671875 34.71875 \n",
       "L 19.671875 8.296875 \n",
       "L 56.78125 8.296875 \n",
       "L 56.78125 0 \n",
       "L 9.8125 0 \n",
       "z\n",
       "\" id=\"BitstreamVeraSans-Roman-45\"/>\n",
       "    </defs>\n",
       "    <g transform=\"translate(131.906825787 97.2062450787)scale(0.18 -0.18)\">\n",
       "     <use xlink:href=\"#BitstreamVeraSans-Roman-45\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"text_5\">\n",
       "    <!-- D -->\n",
       "    <defs>\n",
       "     <path d=\"M 19.671875 64.796875 \n",
       "L 19.671875 8.109375 \n",
       "L 31.59375 8.109375 \n",
       "Q 46.6875 8.109375 53.6875 14.9375 \n",
       "Q 60.6875 21.78125 60.6875 36.53125 \n",
       "Q 60.6875 51.171875 53.6875 57.984375 \n",
       "Q 46.6875 64.796875 31.59375 64.796875 \n",
       "z\n",
       "M 9.8125 72.90625 \n",
       "L 30.078125 72.90625 \n",
       "Q 51.265625 72.90625 61.171875 64.09375 \n",
       "Q 71.09375 55.28125 71.09375 36.53125 \n",
       "Q 71.09375 17.671875 61.125 8.828125 \n",
       "Q 51.171875 0 30.078125 0 \n",
       "L 9.8125 0 \n",
       "z\n",
       "\" id=\"BitstreamVeraSans-Roman-44\"/>\n",
       "    </defs>\n",
       "    <g transform=\"translate(28.6164566929 125.552701772)scale(0.18 -0.18)\">\n",
       "     <use xlink:href=\"#BitstreamVeraSans-Roman-44\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "  </g>\n",
       " </g>\n",
       " <defs>\n",
       "  <clipPath id=\"p7110b7bb3d\">\n",
       "   <rect height=\"170.078740157\" width=\"170.078740157\" x=\"7.2\" y=\"7.2\"/>\n",
       "  </clipPath>\n",
       " </defs>\n",
       "</svg>\n"
      ],
      "text/plain": [
       "<matplotlib.figure.Figure at 0x7feba0b8c0f0>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "pgm = daft.PGM([3, 3], origin=[-0.5, 0.5])\n",
    "add_node(pgm, 'A', 'A', 0, 2.5)\n",
    "add_node(pgm, 'B', 'B', 1, 2.5)\n",
    "add_node(pgm, 'C', 'C', 1, 1.5)\n",
    "add_node(pgm, 'D', 'D', 0, 1.5)\n",
    "add_node(pgm, 'E', 'E', 1.8, 2)\n",
    "add_edges(pgm, [\n",
    "        ('A', 'B'),\n",
    "        ('A', 'D'),\n",
    "        ('C', 'D'),\n",
    "        ('A', 'C'),\n",
    "        ('C', 'E'),\n",
    "        ('B', 'C'),\n",
    "        ('B', 'D'),\n",
    "        ('E', 'B')\n",
    "    ])\n",
    "pgm.render()\n",
    "save('directed')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "image/svg+xml": [
       "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"no\"?>\n",
       "<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\n",
       "  \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n",
       "<!-- Created with matplotlib (http://matplotlib.org/) -->\n",
       "<svg height=\"184pt\" version=\"1.1\" viewBox=\"0 0 184 184\" width=\"184pt\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n",
       " <defs>\n",
       "  <style type=\"text/css\">\n",
       "*{stroke-linecap:butt;stroke-linejoin:round;stroke-miterlimit:100000;}\n",
       "  </style>\n",
       " </defs>\n",
       " <g id=\"figure_1\">\n",
       "  <g id=\"patch_1\">\n",
       "   <path d=\"M 0 184.47874 \n",
       "L 184.47874 184.47874 \n",
       "L 184.47874 0 \n",
       "L 0 0 \n",
       "L 0 184.47874 \n",
       "z\n",
       "\" style=\"fill:none;\"/>\n",
       "  </g>\n",
       "  <g id=\"axes_1\">\n",
       "   <g id=\"patch_2\">\n",
       "    <path clip-path=\"url(#p4b524014f0)\" d=\"M 35.546457 80.900787 \n",
       "C 40.056998 80.900787 44.383406 79.108731 47.57284 75.919296 \n",
       "C 50.762274 72.729862 52.554331 68.403454 52.554331 63.892913 \n",
       "C 52.554331 59.382372 50.762274 55.055964 47.57284 51.86653 \n",
       "C 44.383406 48.677096 40.056998 46.885039 35.546457 46.885039 \n",
       "C 31.035916 46.885039 26.709508 48.677096 23.520074 51.86653 \n",
       "C 20.33064 55.055964 18.538583 59.382372 18.538583 63.892913 \n",
       "C 18.538583 68.403454 20.33064 72.729862 23.520074 75.919296 \n",
       "C 26.709508 79.108731 31.035916 80.900787 35.546457 80.900787 \n",
       "L 35.546457 80.900787 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_3\">\n",
       "    <path clip-path=\"url(#p4b524014f0)\" d=\"M 92.23937 137.593701 \n",
       "C 96.749911 137.593701 101.076319 135.801644 104.265753 132.61221 \n",
       "C 107.455187 129.422776 109.247244 125.096368 109.247244 120.585827 \n",
       "C 109.247244 116.075286 107.455187 111.748878 104.265753 108.559444 \n",
       "C 101.076319 105.37001 96.749911 103.577953 92.23937 103.577953 \n",
       "C 87.728829 103.577953 83.402421 105.37001 80.212987 108.559444 \n",
       "C 77.023553 111.748878 75.231496 116.075286 75.231496 120.585827 \n",
       "C 75.231496 125.096368 77.023553 129.422776 80.212987 132.61221 \n",
       "C 83.402421 135.801644 87.728829 137.593701 92.23937 137.593701 \n",
       "L 92.23937 137.593701 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_4\">\n",
       "    <path clip-path=\"url(#p4b524014f0)\" d=\"M 92.23937 80.900787 \n",
       "C 96.749911 80.900787 101.076319 79.108731 104.265753 75.919296 \n",
       "C 107.455187 72.729862 109.247244 68.403454 109.247244 63.892913 \n",
       "C 109.247244 59.382372 107.455187 55.055964 104.265753 51.86653 \n",
       "C 101.076319 48.677096 96.749911 46.885039 92.23937 46.885039 \n",
       "C 87.728829 46.885039 83.402421 48.677096 80.212987 51.86653 \n",
       "C 77.023553 55.055964 75.231496 59.382372 75.231496 63.892913 \n",
       "C 75.231496 68.403454 77.023553 72.729862 80.212987 75.919296 \n",
       "C 83.402421 79.108731 87.728829 80.900787 92.23937 80.900787 \n",
       "L 92.23937 80.900787 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_5\">\n",
       "    <path clip-path=\"url(#p4b524014f0)\" d=\"M 137.593701 109.247244 \n",
       "C 142.104242 109.247244 146.43065 107.455187 149.620084 104.265753 \n",
       "C 152.809518 101.076319 154.601575 96.749911 154.601575 92.23937 \n",
       "C 154.601575 87.728829 152.809518 83.402421 149.620084 80.212987 \n",
       "C 146.43065 77.023553 142.104242 75.231496 137.593701 75.231496 \n",
       "C 133.08316 75.231496 128.756752 77.023553 125.567318 80.212987 \n",
       "C 122.377884 83.402421 120.585827 87.728829 120.585827 92.23937 \n",
       "C 120.585827 96.749911 122.377884 101.076319 125.567318 104.265753 \n",
       "C 128.756752 107.455187 133.08316 109.247244 137.593701 109.247244 \n",
       "L 137.593701 109.247244 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_6\">\n",
       "    <path clip-path=\"url(#p4b524014f0)\" d=\"M 35.546457 137.593701 \n",
       "C 40.056998 137.593701 44.383406 135.801644 47.57284 132.61221 \n",
       "C 50.762274 129.422776 52.554331 125.096368 52.554331 120.585827 \n",
       "C 52.554331 116.075286 50.762274 111.748878 47.57284 108.559444 \n",
       "C 44.383406 105.37001 40.056998 103.577953 35.546457 103.577953 \n",
       "C 31.035916 103.577953 26.709508 105.37001 23.520074 108.559444 \n",
       "C 20.33064 111.748878 18.538583 116.075286 18.538583 120.585827 \n",
       "C 18.538583 125.096368 20.33064 129.422776 23.520074 132.61221 \n",
       "C 26.709508 135.801644 31.035916 137.593701 35.546457 137.593701 \n",
       "L 35.546457 137.593701 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"line2d_1\">\n",
       "    <path clip-path=\"url(#p4b524014f0)\" d=\"M 52.554331 63.892913 \n",
       "L 75.231496 63.892913 \n",
       "\" style=\"fill:none;stroke:#000000;stroke-linecap:square;\"/>\n",
       "   </g>\n",
       "   <g id=\"line2d_2\">\n",
       "    <path clip-path=\"url(#p4b524014f0)\" d=\"M 35.546457 80.900787 \n",
       "L 35.546457 103.577953 \n",
       "\" style=\"fill:none;stroke:#000000;stroke-linecap:square;\"/>\n",
       "   </g>\n",
       "   <g id=\"line2d_3\">\n",
       "    <path clip-path=\"url(#p4b524014f0)\" d=\"M 75.231496 120.585827 \n",
       "L 52.554331 120.585827 \n",
       "\" style=\"fill:none;stroke:#000000;stroke-linecap:square;\"/>\n",
       "   </g>\n",
       "   <g id=\"line2d_4\">\n",
       "    <path clip-path=\"url(#p4b524014f0)\" d=\"M 47.57284 75.919296 \n",
       "L 80.212987 108.559444 \n",
       "\" style=\"fill:none;stroke:#000000;stroke-linecap:square;\"/>\n",
       "   </g>\n",
       "   <g id=\"line2d_5\">\n",
       "    <path clip-path=\"url(#p4b524014f0)\" d=\"M 106.662018 111.571672 \n",
       "L 123.171052 101.253525 \n",
       "\" style=\"fill:none;stroke:#000000;stroke-linecap:square;\"/>\n",
       "   </g>\n",
       "   <g id=\"line2d_6\">\n",
       "    <path clip-path=\"url(#p4b524014f0)\" d=\"M 92.23937 80.900787 \n",
       "L 92.23937 103.577953 \n",
       "\" style=\"fill:none;stroke:#000000;stroke-linecap:square;\"/>\n",
       "   </g>\n",
       "   <g id=\"line2d_7\">\n",
       "    <path clip-path=\"url(#p4b524014f0)\" d=\"M 80.212987 75.919296 \n",
       "L 47.57284 108.559444 \n",
       "\" style=\"fill:none;stroke:#000000;stroke-linecap:square;\"/>\n",
       "   </g>\n",
       "   <g id=\"line2d_8\">\n",
       "    <path clip-path=\"url(#p4b524014f0)\" d=\"M 123.171052 83.225215 \n",
       "L 106.662018 72.907069 \n",
       "\" style=\"fill:none;stroke:#000000;stroke-linecap:square;\"/>\n",
       "   </g>\n",
       "   <g id=\"matplotlib.axis_1\"/>\n",
       "   <g id=\"matplotlib.axis_2\"/>\n",
       "   <g id=\"text_1\">\n",
       "    <!-- A -->\n",
       "    <defs>\n",
       "     <path d=\"M 34.1875 63.1875 \n",
       "L 20.796875 26.90625 \n",
       "L 47.609375 26.90625 \n",
       "z\n",
       "M 28.609375 72.90625 \n",
       "L 39.796875 72.90625 \n",
       "L 67.578125 0 \n",
       "L 57.328125 0 \n",
       "L 50.6875 18.703125 \n",
       "L 17.828125 18.703125 \n",
       "L 11.1875 0 \n",
       "L 0.78125 0 \n",
       "z\n",
       "\" id=\"BitstreamVeraSans-Roman-41\"/>\n",
       "    </defs>\n",
       "    <g transform=\"translate(29.3898941929 68.8597883858)scale(0.18 -0.18)\">\n",
       "     <use xlink:href=\"#BitstreamVeraSans-Roman-41\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"text_2\">\n",
       "    <!-- C -->\n",
       "    <defs>\n",
       "     <path d=\"M 64.40625 67.28125 \n",
       "L 64.40625 56.890625 \n",
       "Q 59.421875 61.53125 53.78125 63.8125 \n",
       "Q 48.140625 66.109375 41.796875 66.109375 \n",
       "Q 29.296875 66.109375 22.65625 58.46875 \n",
       "Q 16.015625 50.828125 16.015625 36.375 \n",
       "Q 16.015625 21.96875 22.65625 14.328125 \n",
       "Q 29.296875 6.6875 41.796875 6.6875 \n",
       "Q 48.140625 6.6875 53.78125 8.984375 \n",
       "Q 59.421875 11.28125 64.40625 15.921875 \n",
       "L 64.40625 5.609375 \n",
       "Q 59.234375 2.09375 53.4375 0.328125 \n",
       "Q 47.65625 -1.421875 41.21875 -1.421875 \n",
       "Q 24.65625 -1.421875 15.125 8.703125 \n",
       "Q 5.609375 18.84375 5.609375 36.375 \n",
       "Q 5.609375 53.953125 15.125 64.078125 \n",
       "Q 24.65625 74.21875 41.21875 74.21875 \n",
       "Q 47.75 74.21875 53.53125 72.484375 \n",
       "Q 59.328125 70.75 64.40625 67.28125 \n",
       "\" id=\"BitstreamVeraSans-Roman-43\"/>\n",
       "    </defs>\n",
       "    <g transform=\"translate(85.9548388287 125.552701772)scale(0.18 -0.18)\">\n",
       "     <use xlink:href=\"#BitstreamVeraSans-Roman-43\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"text_3\">\n",
       "    <!-- B -->\n",
       "    <defs>\n",
       "     <path d=\"M 19.671875 34.8125 \n",
       "L 19.671875 8.109375 \n",
       "L 35.5 8.109375 \n",
       "Q 43.453125 8.109375 47.28125 11.40625 \n",
       "Q 51.125 14.703125 51.125 21.484375 \n",
       "Q 51.125 28.328125 47.28125 31.5625 \n",
       "Q 43.453125 34.8125 35.5 34.8125 \n",
       "z\n",
       "M 19.671875 64.796875 \n",
       "L 19.671875 42.828125 \n",
       "L 34.28125 42.828125 \n",
       "Q 41.5 42.828125 45.03125 45.53125 \n",
       "Q 48.578125 48.25 48.578125 53.8125 \n",
       "Q 48.578125 59.328125 45.03125 62.0625 \n",
       "Q 41.5 64.796875 34.28125 64.796875 \n",
       "z\n",
       "M 9.8125 72.90625 \n",
       "L 35.015625 72.90625 \n",
       "Q 46.296875 72.90625 52.390625 68.21875 \n",
       "Q 58.5 63.53125 58.5 54.890625 \n",
       "Q 58.5 48.1875 55.375 44.234375 \n",
       "Q 52.25 40.28125 46.1875 39.3125 \n",
       "Q 53.46875 37.75 57.5 32.78125 \n",
       "Q 61.53125 27.828125 61.53125 20.40625 \n",
       "Q 61.53125 10.640625 54.890625 5.3125 \n",
       "Q 48.25 0 35.984375 0 \n",
       "L 9.8125 0 \n",
       "z\n",
       "\" id=\"BitstreamVeraSans-Roman-42\"/>\n",
       "    </defs>\n",
       "    <g transform=\"translate(86.0645263287 68.8597883858)scale(0.18 -0.18)\">\n",
       "     <use xlink:href=\"#BitstreamVeraSans-Roman-42\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"text_4\">\n",
       "    <!-- E -->\n",
       "    <defs>\n",
       "     <path d=\"M 9.8125 72.90625 \n",
       "L 55.90625 72.90625 \n",
       "L 55.90625 64.59375 \n",
       "L 19.671875 64.59375 \n",
       "L 19.671875 43.015625 \n",
       "L 54.390625 43.015625 \n",
       "L 54.390625 34.71875 \n",
       "L 19.671875 34.71875 \n",
       "L 19.671875 8.296875 \n",
       "L 56.78125 8.296875 \n",
       "L 56.78125 0 \n",
       "L 9.8125 0 \n",
       "z\n",
       "\" id=\"BitstreamVeraSans-Roman-45\"/>\n",
       "    </defs>\n",
       "    <g transform=\"translate(131.906825787 97.2062450787)scale(0.18 -0.18)\">\n",
       "     <use xlink:href=\"#BitstreamVeraSans-Roman-45\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"text_5\">\n",
       "    <!-- D -->\n",
       "    <defs>\n",
       "     <path d=\"M 19.671875 64.796875 \n",
       "L 19.671875 8.109375 \n",
       "L 31.59375 8.109375 \n",
       "Q 46.6875 8.109375 53.6875 14.9375 \n",
       "Q 60.6875 21.78125 60.6875 36.53125 \n",
       "Q 60.6875 51.171875 53.6875 57.984375 \n",
       "Q 46.6875 64.796875 31.59375 64.796875 \n",
       "z\n",
       "M 9.8125 72.90625 \n",
       "L 30.078125 72.90625 \n",
       "Q 51.265625 72.90625 61.171875 64.09375 \n",
       "Q 71.09375 55.28125 71.09375 36.53125 \n",
       "Q 71.09375 17.671875 61.125 8.828125 \n",
       "Q 51.171875 0 30.078125 0 \n",
       "L 9.8125 0 \n",
       "z\n",
       "\" id=\"BitstreamVeraSans-Roman-44\"/>\n",
       "    </defs>\n",
       "    <g transform=\"translate(28.6164566929 125.552701772)scale(0.18 -0.18)\">\n",
       "     <use xlink:href=\"#BitstreamVeraSans-Roman-44\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "  </g>\n",
       " </g>\n",
       " <defs>\n",
       "  <clipPath id=\"p4b524014f0\">\n",
       "   <rect height=\"170.078740157\" width=\"170.078740157\" x=\"7.2\" y=\"7.2\"/>\n",
       "  </clipPath>\n",
       " </defs>\n",
       "</svg>\n"
      ],
      "text/plain": [
       "<matplotlib.figure.Figure at 0x7feba0b8c128>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "pgm = daft.PGM([3, 3], origin=[-0.5, 0.5], directed=False)\n",
    "add_node(pgm, 'A', 'A', 0, 2.5)\n",
    "add_node(pgm, 'B', 'B', 1, 2.5)\n",
    "add_node(pgm, 'C', 'C', 1, 1.5)\n",
    "add_node(pgm, 'D', 'D', 0, 1.5)\n",
    "add_node(pgm, 'E', 'E', 1.8, 2)\n",
    "add_edges(pgm, [\n",
    "        ('A', 'B'),\n",
    "        ('A', 'D'),\n",
    "        ('C', 'D'),\n",
    "        ('A', 'C'),\n",
    "        ('C', 'E'),\n",
    "        ('B', 'C'),\n",
    "        ('B', 'D'),\n",
    "        ('E', 'B')\n",
    "    ])\n",
    "pgm.render()\n",
    "save('undirected')\n",
    "save('clique_example')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "image/svg+xml": [
       "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"no\"?>\n",
       "<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\n",
       "  \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n",
       "<!-- Created with matplotlib (http://matplotlib.org/) -->\n",
       "<svg height=\"184pt\" version=\"1.1\" viewBox=\"0 0 184 184\" width=\"184pt\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n",
       " <defs>\n",
       "  <style type=\"text/css\">\n",
       "*{stroke-linecap:butt;stroke-linejoin:round;stroke-miterlimit:100000;}\n",
       "  </style>\n",
       " </defs>\n",
       " <g id=\"figure_1\">\n",
       "  <g id=\"patch_1\">\n",
       "   <path d=\"M 0 184.47874 \n",
       "L 184.47874 184.47874 \n",
       "L 184.47874 0 \n",
       "L 0 0 \n",
       "L 0 184.47874 \n",
       "z\n",
       "\" style=\"fill:none;\"/>\n",
       "  </g>\n",
       "  <g id=\"axes_1\">\n",
       "   <g id=\"patch_2\">\n",
       "    <path clip-path=\"url(#p98a71b8f83)\" d=\"M 80.212987 108.559444 \n",
       "L 76.705292 108.058344 \n",
       "L 78.20859 106.555047 \n",
       "L 47.57284 75.919296 \n",
       "L 47.57284 75.919296 \n",
       "L 78.20859 106.555047 \n",
       "L 79.711888 105.051749 \n",
       "L 80.212987 108.559444 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_3\">\n",
       "    <path clip-path=\"url(#p98a71b8f83)\" d=\"M 123.171052 101.253525 \n",
       "L 121.894047 104.558716 \n",
       "L 120.767278 102.755884 \n",
       "L 106.662018 111.571672 \n",
       "L 106.662018 111.571672 \n",
       "L 120.767278 102.755884 \n",
       "L 119.640508 100.953053 \n",
       "L 123.171052 101.253525 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_4\">\n",
       "    <path clip-path=\"url(#p98a71b8f83)\" d=\"M 106.662018 72.907069 \n",
       "L 110.192563 72.606597 \n",
       "L 109.065793 74.409428 \n",
       "L 123.171052 83.225215 \n",
       "L 123.171052 83.225215 \n",
       "L 109.065793 74.409428 \n",
       "L 107.939024 76.212259 \n",
       "L 106.662018 72.907069 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_5\">\n",
       "    <path clip-path=\"url(#p98a71b8f83)\" d=\"M 35.546457 80.900787 \n",
       "C 40.056998 80.900787 44.383406 79.108731 47.57284 75.919296 \n",
       "C 50.762274 72.729862 52.554331 68.403454 52.554331 63.892913 \n",
       "C 52.554331 59.382372 50.762274 55.055964 47.57284 51.86653 \n",
       "C 44.383406 48.677096 40.056998 46.885039 35.546457 46.885039 \n",
       "C 31.035916 46.885039 26.709508 48.677096 23.520074 51.86653 \n",
       "C 20.33064 55.055964 18.538583 59.382372 18.538583 63.892913 \n",
       "C 18.538583 68.403454 20.33064 72.729862 23.520074 75.919296 \n",
       "C 26.709508 79.108731 31.035916 80.900787 35.546457 80.900787 \n",
       "L 35.546457 80.900787 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_6\">\n",
       "    <path clip-path=\"url(#p98a71b8f83)\" d=\"M 92.23937 137.593701 \n",
       "C 96.749911 137.593701 101.076319 135.801644 104.265753 132.61221 \n",
       "C 107.455187 129.422776 109.247244 125.096368 109.247244 120.585827 \n",
       "C 109.247244 116.075286 107.455187 111.748878 104.265753 108.559444 \n",
       "C 101.076319 105.37001 96.749911 103.577953 92.23937 103.577953 \n",
       "C 87.728829 103.577953 83.402421 105.37001 80.212987 108.559444 \n",
       "C 77.023553 111.748878 75.231496 116.075286 75.231496 120.585827 \n",
       "C 75.231496 125.096368 77.023553 129.422776 80.212987 132.61221 \n",
       "C 83.402421 135.801644 87.728829 137.593701 92.23937 137.593701 \n",
       "L 92.23937 137.593701 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_7\">\n",
       "    <path clip-path=\"url(#p98a71b8f83)\" d=\"M 92.23937 80.900787 \n",
       "C 96.749911 80.900787 101.076319 79.108731 104.265753 75.919296 \n",
       "C 107.455187 72.729862 109.247244 68.403454 109.247244 63.892913 \n",
       "C 109.247244 59.382372 107.455187 55.055964 104.265753 51.86653 \n",
       "C 101.076319 48.677096 96.749911 46.885039 92.23937 46.885039 \n",
       "C 87.728829 46.885039 83.402421 48.677096 80.212987 51.86653 \n",
       "C 77.023553 55.055964 75.231496 59.382372 75.231496 63.892913 \n",
       "C 75.231496 68.403454 77.023553 72.729862 80.212987 75.919296 \n",
       "C 83.402421 79.108731 87.728829 80.900787 92.23937 80.900787 \n",
       "L 92.23937 80.900787 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_8\">\n",
       "    <path clip-path=\"url(#p98a71b8f83)\" d=\"M 137.593701 109.247244 \n",
       "C 142.104242 109.247244 146.43065 107.455187 149.620084 104.265753 \n",
       "C 152.809518 101.076319 154.601575 96.749911 154.601575 92.23937 \n",
       "C 154.601575 87.728829 152.809518 83.402421 149.620084 80.212987 \n",
       "C 146.43065 77.023553 142.104242 75.231496 137.593701 75.231496 \n",
       "C 133.08316 75.231496 128.756752 77.023553 125.567318 80.212987 \n",
       "C 122.377884 83.402421 120.585827 87.728829 120.585827 92.23937 \n",
       "C 120.585827 96.749911 122.377884 101.076319 125.567318 104.265753 \n",
       "C 128.756752 107.455187 133.08316 109.247244 137.593701 109.247244 \n",
       "L 137.593701 109.247244 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_9\">\n",
       "    <path clip-path=\"url(#p98a71b8f83)\" d=\"M 35.546457 137.593701 \n",
       "C 40.056998 137.593701 44.383406 135.801644 47.57284 132.61221 \n",
       "C 50.762274 129.422776 52.554331 125.096368 52.554331 120.585827 \n",
       "C 52.554331 116.075286 50.762274 111.748878 47.57284 108.559444 \n",
       "C 44.383406 105.37001 40.056998 103.577953 35.546457 103.577953 \n",
       "C 31.035916 103.577953 26.709508 105.37001 23.520074 108.559444 \n",
       "C 20.33064 111.748878 18.538583 116.075286 18.538583 120.585827 \n",
       "C 18.538583 125.096368 20.33064 129.422776 23.520074 132.61221 \n",
       "C 26.709508 135.801644 31.035916 137.593701 35.546457 137.593701 \n",
       "L 35.546457 137.593701 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"matplotlib.axis_1\"/>\n",
       "   <g id=\"matplotlib.axis_2\"/>\n",
       "   <g id=\"text_1\">\n",
       "    <!-- A -->\n",
       "    <defs>\n",
       "     <path d=\"M 34.1875 63.1875 \n",
       "L 20.796875 26.90625 \n",
       "L 47.609375 26.90625 \n",
       "z\n",
       "M 28.609375 72.90625 \n",
       "L 39.796875 72.90625 \n",
       "L 67.578125 0 \n",
       "L 57.328125 0 \n",
       "L 50.6875 18.703125 \n",
       "L 17.828125 18.703125 \n",
       "L 11.1875 0 \n",
       "L 0.78125 0 \n",
       "z\n",
       "\" id=\"BitstreamVeraSans-Roman-41\"/>\n",
       "    </defs>\n",
       "    <g transform=\"translate(29.3898941929 68.8597883858)scale(0.18 -0.18)\">\n",
       "     <use xlink:href=\"#BitstreamVeraSans-Roman-41\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"text_2\">\n",
       "    <!-- C -->\n",
       "    <defs>\n",
       "     <path d=\"M 64.40625 67.28125 \n",
       "L 64.40625 56.890625 \n",
       "Q 59.421875 61.53125 53.78125 63.8125 \n",
       "Q 48.140625 66.109375 41.796875 66.109375 \n",
       "Q 29.296875 66.109375 22.65625 58.46875 \n",
       "Q 16.015625 50.828125 16.015625 36.375 \n",
       "Q 16.015625 21.96875 22.65625 14.328125 \n",
       "Q 29.296875 6.6875 41.796875 6.6875 \n",
       "Q 48.140625 6.6875 53.78125 8.984375 \n",
       "Q 59.421875 11.28125 64.40625 15.921875 \n",
       "L 64.40625 5.609375 \n",
       "Q 59.234375 2.09375 53.4375 0.328125 \n",
       "Q 47.65625 -1.421875 41.21875 -1.421875 \n",
       "Q 24.65625 -1.421875 15.125 8.703125 \n",
       "Q 5.609375 18.84375 5.609375 36.375 \n",
       "Q 5.609375 53.953125 15.125 64.078125 \n",
       "Q 24.65625 74.21875 41.21875 74.21875 \n",
       "Q 47.75 74.21875 53.53125 72.484375 \n",
       "Q 59.328125 70.75 64.40625 67.28125 \n",
       "\" id=\"BitstreamVeraSans-Roman-43\"/>\n",
       "    </defs>\n",
       "    <g transform=\"translate(85.9548388287 125.552701772)scale(0.18 -0.18)\">\n",
       "     <use xlink:href=\"#BitstreamVeraSans-Roman-43\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"text_3\">\n",
       "    <!-- B -->\n",
       "    <defs>\n",
       "     <path d=\"M 19.671875 34.8125 \n",
       "L 19.671875 8.109375 \n",
       "L 35.5 8.109375 \n",
       "Q 43.453125 8.109375 47.28125 11.40625 \n",
       "Q 51.125 14.703125 51.125 21.484375 \n",
       "Q 51.125 28.328125 47.28125 31.5625 \n",
       "Q 43.453125 34.8125 35.5 34.8125 \n",
       "z\n",
       "M 19.671875 64.796875 \n",
       "L 19.671875 42.828125 \n",
       "L 34.28125 42.828125 \n",
       "Q 41.5 42.828125 45.03125 45.53125 \n",
       "Q 48.578125 48.25 48.578125 53.8125 \n",
       "Q 48.578125 59.328125 45.03125 62.0625 \n",
       "Q 41.5 64.796875 34.28125 64.796875 \n",
       "z\n",
       "M 9.8125 72.90625 \n",
       "L 35.015625 72.90625 \n",
       "Q 46.296875 72.90625 52.390625 68.21875 \n",
       "Q 58.5 63.53125 58.5 54.890625 \n",
       "Q 58.5 48.1875 55.375 44.234375 \n",
       "Q 52.25 40.28125 46.1875 39.3125 \n",
       "Q 53.46875 37.75 57.5 32.78125 \n",
       "Q 61.53125 27.828125 61.53125 20.40625 \n",
       "Q 61.53125 10.640625 54.890625 5.3125 \n",
       "Q 48.25 0 35.984375 0 \n",
       "L 9.8125 0 \n",
       "z\n",
       "\" id=\"BitstreamVeraSans-Roman-42\"/>\n",
       "    </defs>\n",
       "    <g transform=\"translate(86.0645263287 68.8597883858)scale(0.18 -0.18)\">\n",
       "     <use xlink:href=\"#BitstreamVeraSans-Roman-42\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"text_4\">\n",
       "    <!-- E -->\n",
       "    <defs>\n",
       "     <path d=\"M 9.8125 72.90625 \n",
       "L 55.90625 72.90625 \n",
       "L 55.90625 64.59375 \n",
       "L 19.671875 64.59375 \n",
       "L 19.671875 43.015625 \n",
       "L 54.390625 43.015625 \n",
       "L 54.390625 34.71875 \n",
       "L 19.671875 34.71875 \n",
       "L 19.671875 8.296875 \n",
       "L 56.78125 8.296875 \n",
       "L 56.78125 0 \n",
       "L 9.8125 0 \n",
       "z\n",
       "\" id=\"BitstreamVeraSans-Roman-45\"/>\n",
       "    </defs>\n",
       "    <g transform=\"translate(131.906825787 97.2062450787)scale(0.18 -0.18)\">\n",
       "     <use xlink:href=\"#BitstreamVeraSans-Roman-45\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"text_5\">\n",
       "    <!-- D -->\n",
       "    <defs>\n",
       "     <path d=\"M 19.671875 64.796875 \n",
       "L 19.671875 8.109375 \n",
       "L 31.59375 8.109375 \n",
       "Q 46.6875 8.109375 53.6875 14.9375 \n",
       "Q 60.6875 21.78125 60.6875 36.53125 \n",
       "Q 60.6875 51.171875 53.6875 57.984375 \n",
       "Q 46.6875 64.796875 31.59375 64.796875 \n",
       "z\n",
       "M 9.8125 72.90625 \n",
       "L 30.078125 72.90625 \n",
       "Q 51.265625 72.90625 61.171875 64.09375 \n",
       "Q 71.09375 55.28125 71.09375 36.53125 \n",
       "Q 71.09375 17.671875 61.125 8.828125 \n",
       "Q 51.171875 0 30.078125 0 \n",
       "L 9.8125 0 \n",
       "z\n",
       "\" id=\"BitstreamVeraSans-Roman-44\"/>\n",
       "    </defs>\n",
       "    <g transform=\"translate(28.6164566929 125.552701772)scale(0.18 -0.18)\">\n",
       "     <use xlink:href=\"#BitstreamVeraSans-Roman-44\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "  </g>\n",
       " </g>\n",
       " <defs>\n",
       "  <clipPath id=\"p98a71b8f83\">\n",
       "   <rect height=\"170.078740157\" width=\"170.078740157\" x=\"7.2\" y=\"7.2\"/>\n",
       "  </clipPath>\n",
       " </defs>\n",
       "</svg>\n"
      ],
      "text/plain": [
       "<matplotlib.figure.Figure at 0x7feba0b8c588>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "pgm = daft.PGM([3, 3], origin=[-0.5, 0.5])\n",
    "add_node(pgm, 'A', 'A', 0, 2.5)\n",
    "add_node(pgm, 'B', 'B', 1, 2.5)\n",
    "add_node(pgm, 'C', 'C', 1, 1.5)\n",
    "add_node(pgm, 'D', 'D', 0, 1.5)\n",
    "add_node(pgm, 'E', 'E', 1.8, 2)\n",
    "add_edges(pgm, [\n",
    "        ('A', 'C'),\n",
    "        ('C', 'E'),\n",
    "        ('E', 'B'),\n",
    "    ])\n",
    "pgm.render()\n",
    "save('graph_example')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "image/svg+xml": [
       "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"no\"?>\n",
       "<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\n",
       "  \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n",
       "<!-- Created with matplotlib (http://matplotlib.org/) -->\n",
       "<svg height=\"184pt\" version=\"1.1\" viewBox=\"0 0 184 184\" width=\"184pt\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n",
       " <defs>\n",
       "  <style type=\"text/css\">\n",
       "*{stroke-linecap:butt;stroke-linejoin:round;stroke-miterlimit:100000;}\n",
       "  </style>\n",
       " </defs>\n",
       " <g id=\"figure_1\">\n",
       "  <g id=\"patch_1\">\n",
       "   <path d=\"M 0 184.47874 \n",
       "L 184.47874 184.47874 \n",
       "L 184.47874 0 \n",
       "L 0 0 \n",
       "L 0 184.47874 \n",
       "z\n",
       "\" style=\"fill:none;\"/>\n",
       "  </g>\n",
       "  <g id=\"axes_1\">\n",
       "   <g id=\"patch_2\">\n",
       "    <path clip-path=\"url(#paf49570c8d)\" d=\"M 52.554331 63.892913 \n",
       "L 55.388976 61.766929 \n",
       "L 55.388976 63.892913 \n",
       "L 75.231496 63.892913 \n",
       "L 75.231496 63.892913 \n",
       "L 55.388976 63.892913 \n",
       "L 55.388976 66.018898 \n",
       "L 52.554331 63.892913 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_3\">\n",
       "    <path clip-path=\"url(#paf49570c8d)\" d=\"M 92.23937 80.900787 \n",
       "L 94.365354 83.735433 \n",
       "L 92.23937 83.735433 \n",
       "L 92.23937 103.577953 \n",
       "L 92.23937 103.577953 \n",
       "L 92.23937 83.735433 \n",
       "L 90.113386 83.735433 \n",
       "L 92.23937 80.900787 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_4\">\n",
       "    <path clip-path=\"url(#paf49570c8d)\" d=\"M 75.231496 120.585827 \n",
       "L 72.39685 122.711811 \n",
       "L 72.39685 120.585827 \n",
       "L 52.554331 120.585827 \n",
       "L 52.554331 120.585827 \n",
       "L 72.39685 120.585827 \n",
       "L 72.39685 118.459843 \n",
       "L 75.231496 120.585827 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_5\">\n",
       "    <path clip-path=\"url(#paf49570c8d)\" d=\"M 35.546457 103.577953 \n",
       "L 33.420472 100.743307 \n",
       "L 35.546457 100.743307 \n",
       "L 35.546457 80.900787 \n",
       "L 35.546457 80.900787 \n",
       "L 35.546457 100.743307 \n",
       "L 37.672441 100.743307 \n",
       "L 35.546457 103.577953 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_6\">\n",
       "    <path clip-path=\"url(#paf49570c8d)\" d=\"M 35.546457 80.900787 \n",
       "C 40.056998 80.900787 44.383406 79.108731 47.57284 75.919296 \n",
       "C 50.762274 72.729862 52.554331 68.403454 52.554331 63.892913 \n",
       "C 52.554331 59.382372 50.762274 55.055964 47.57284 51.86653 \n",
       "C 44.383406 48.677096 40.056998 46.885039 35.546457 46.885039 \n",
       "C 31.035916 46.885039 26.709508 48.677096 23.520074 51.86653 \n",
       "C 20.33064 55.055964 18.538583 59.382372 18.538583 63.892913 \n",
       "C 18.538583 68.403454 20.33064 72.729862 23.520074 75.919296 \n",
       "C 26.709508 79.108731 31.035916 80.900787 35.546457 80.900787 \n",
       "L 35.546457 80.900787 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_7\">\n",
       "    <path clip-path=\"url(#paf49570c8d)\" d=\"M 92.23937 137.593701 \n",
       "C 96.749911 137.593701 101.076319 135.801644 104.265753 132.61221 \n",
       "C 107.455187 129.422776 109.247244 125.096368 109.247244 120.585827 \n",
       "C 109.247244 116.075286 107.455187 111.748878 104.265753 108.559444 \n",
       "C 101.076319 105.37001 96.749911 103.577953 92.23937 103.577953 \n",
       "C 87.728829 103.577953 83.402421 105.37001 80.212987 108.559444 \n",
       "C 77.023553 111.748878 75.231496 116.075286 75.231496 120.585827 \n",
       "C 75.231496 125.096368 77.023553 129.422776 80.212987 132.61221 \n",
       "C 83.402421 135.801644 87.728829 137.593701 92.23937 137.593701 \n",
       "L 92.23937 137.593701 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_8\">\n",
       "    <path clip-path=\"url(#paf49570c8d)\" d=\"M 92.23937 80.900787 \n",
       "C 96.749911 80.900787 101.076319 79.108731 104.265753 75.919296 \n",
       "C 107.455187 72.729862 109.247244 68.403454 109.247244 63.892913 \n",
       "C 109.247244 59.382372 107.455187 55.055964 104.265753 51.86653 \n",
       "C 101.076319 48.677096 96.749911 46.885039 92.23937 46.885039 \n",
       "C 87.728829 46.885039 83.402421 48.677096 80.212987 51.86653 \n",
       "C 77.023553 55.055964 75.231496 59.382372 75.231496 63.892913 \n",
       "C 75.231496 68.403454 77.023553 72.729862 80.212987 75.919296 \n",
       "C 83.402421 79.108731 87.728829 80.900787 92.23937 80.900787 \n",
       "L 92.23937 80.900787 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_9\">\n",
       "    <path clip-path=\"url(#paf49570c8d)\" d=\"M 137.593701 109.247244 \n",
       "C 142.104242 109.247244 146.43065 107.455187 149.620084 104.265753 \n",
       "C 152.809518 101.076319 154.601575 96.749911 154.601575 92.23937 \n",
       "C 154.601575 87.728829 152.809518 83.402421 149.620084 80.212987 \n",
       "C 146.43065 77.023553 142.104242 75.231496 137.593701 75.231496 \n",
       "C 133.08316 75.231496 128.756752 77.023553 125.567318 80.212987 \n",
       "C 122.377884 83.402421 120.585827 87.728829 120.585827 92.23937 \n",
       "C 120.585827 96.749911 122.377884 101.076319 125.567318 104.265753 \n",
       "C 128.756752 107.455187 133.08316 109.247244 137.593701 109.247244 \n",
       "L 137.593701 109.247244 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_10\">\n",
       "    <path clip-path=\"url(#paf49570c8d)\" d=\"M 35.546457 137.593701 \n",
       "C 40.056998 137.593701 44.383406 135.801644 47.57284 132.61221 \n",
       "C 50.762274 129.422776 52.554331 125.096368 52.554331 120.585827 \n",
       "C 52.554331 116.075286 50.762274 111.748878 47.57284 108.559444 \n",
       "C 44.383406 105.37001 40.056998 103.577953 35.546457 103.577953 \n",
       "C 31.035916 103.577953 26.709508 105.37001 23.520074 108.559444 \n",
       "C 20.33064 111.748878 18.538583 116.075286 18.538583 120.585827 \n",
       "C 18.538583 125.096368 20.33064 129.422776 23.520074 132.61221 \n",
       "C 26.709508 135.801644 31.035916 137.593701 35.546457 137.593701 \n",
       "L 35.546457 137.593701 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"matplotlib.axis_1\"/>\n",
       "   <g id=\"matplotlib.axis_2\"/>\n",
       "   <g id=\"text_1\">\n",
       "    <!-- A -->\n",
       "    <defs>\n",
       "     <path d=\"M 34.1875 63.1875 \n",
       "L 20.796875 26.90625 \n",
       "L 47.609375 26.90625 \n",
       "z\n",
       "M 28.609375 72.90625 \n",
       "L 39.796875 72.90625 \n",
       "L 67.578125 0 \n",
       "L 57.328125 0 \n",
       "L 50.6875 18.703125 \n",
       "L 17.828125 18.703125 \n",
       "L 11.1875 0 \n",
       "L 0.78125 0 \n",
       "z\n",
       "\" id=\"BitstreamVeraSans-Roman-41\"/>\n",
       "    </defs>\n",
       "    <g transform=\"translate(29.3898941929 68.8597883858)scale(0.18 -0.18)\">\n",
       "     <use xlink:href=\"#BitstreamVeraSans-Roman-41\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"text_2\">\n",
       "    <!-- C -->\n",
       "    <defs>\n",
       "     <path d=\"M 64.40625 67.28125 \n",
       "L 64.40625 56.890625 \n",
       "Q 59.421875 61.53125 53.78125 63.8125 \n",
       "Q 48.140625 66.109375 41.796875 66.109375 \n",
       "Q 29.296875 66.109375 22.65625 58.46875 \n",
       "Q 16.015625 50.828125 16.015625 36.375 \n",
       "Q 16.015625 21.96875 22.65625 14.328125 \n",
       "Q 29.296875 6.6875 41.796875 6.6875 \n",
       "Q 48.140625 6.6875 53.78125 8.984375 \n",
       "Q 59.421875 11.28125 64.40625 15.921875 \n",
       "L 64.40625 5.609375 \n",
       "Q 59.234375 2.09375 53.4375 0.328125 \n",
       "Q 47.65625 -1.421875 41.21875 -1.421875 \n",
       "Q 24.65625 -1.421875 15.125 8.703125 \n",
       "Q 5.609375 18.84375 5.609375 36.375 \n",
       "Q 5.609375 53.953125 15.125 64.078125 \n",
       "Q 24.65625 74.21875 41.21875 74.21875 \n",
       "Q 47.75 74.21875 53.53125 72.484375 \n",
       "Q 59.328125 70.75 64.40625 67.28125 \n",
       "\" id=\"BitstreamVeraSans-Roman-43\"/>\n",
       "    </defs>\n",
       "    <g transform=\"translate(85.9548388287 125.552701772)scale(0.18 -0.18)\">\n",
       "     <use xlink:href=\"#BitstreamVeraSans-Roman-43\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"text_3\">\n",
       "    <!-- B -->\n",
       "    <defs>\n",
       "     <path d=\"M 19.671875 34.8125 \n",
       "L 19.671875 8.109375 \n",
       "L 35.5 8.109375 \n",
       "Q 43.453125 8.109375 47.28125 11.40625 \n",
       "Q 51.125 14.703125 51.125 21.484375 \n",
       "Q 51.125 28.328125 47.28125 31.5625 \n",
       "Q 43.453125 34.8125 35.5 34.8125 \n",
       "z\n",
       "M 19.671875 64.796875 \n",
       "L 19.671875 42.828125 \n",
       "L 34.28125 42.828125 \n",
       "Q 41.5 42.828125 45.03125 45.53125 \n",
       "Q 48.578125 48.25 48.578125 53.8125 \n",
       "Q 48.578125 59.328125 45.03125 62.0625 \n",
       "Q 41.5 64.796875 34.28125 64.796875 \n",
       "z\n",
       "M 9.8125 72.90625 \n",
       "L 35.015625 72.90625 \n",
       "Q 46.296875 72.90625 52.390625 68.21875 \n",
       "Q 58.5 63.53125 58.5 54.890625 \n",
       "Q 58.5 48.1875 55.375 44.234375 \n",
       "Q 52.25 40.28125 46.1875 39.3125 \n",
       "Q 53.46875 37.75 57.5 32.78125 \n",
       "Q 61.53125 27.828125 61.53125 20.40625 \n",
       "Q 61.53125 10.640625 54.890625 5.3125 \n",
       "Q 48.25 0 35.984375 0 \n",
       "L 9.8125 0 \n",
       "z\n",
       "\" id=\"BitstreamVeraSans-Roman-42\"/>\n",
       "    </defs>\n",
       "    <g transform=\"translate(86.0645263287 68.8597883858)scale(0.18 -0.18)\">\n",
       "     <use xlink:href=\"#BitstreamVeraSans-Roman-42\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"text_4\">\n",
       "    <!-- E -->\n",
       "    <defs>\n",
       "     <path d=\"M 9.8125 72.90625 \n",
       "L 55.90625 72.90625 \n",
       "L 55.90625 64.59375 \n",
       "L 19.671875 64.59375 \n",
       "L 19.671875 43.015625 \n",
       "L 54.390625 43.015625 \n",
       "L 54.390625 34.71875 \n",
       "L 19.671875 34.71875 \n",
       "L 19.671875 8.296875 \n",
       "L 56.78125 8.296875 \n",
       "L 56.78125 0 \n",
       "L 9.8125 0 \n",
       "z\n",
       "\" id=\"BitstreamVeraSans-Roman-45\"/>\n",
       "    </defs>\n",
       "    <g transform=\"translate(131.906825787 97.2062450787)scale(0.18 -0.18)\">\n",
       "     <use xlink:href=\"#BitstreamVeraSans-Roman-45\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"text_5\">\n",
       "    <!-- D -->\n",
       "    <defs>\n",
       "     <path d=\"M 19.671875 64.796875 \n",
       "L 19.671875 8.109375 \n",
       "L 31.59375 8.109375 \n",
       "Q 46.6875 8.109375 53.6875 14.9375 \n",
       "Q 60.6875 21.78125 60.6875 36.53125 \n",
       "Q 60.6875 51.171875 53.6875 57.984375 \n",
       "Q 46.6875 64.796875 31.59375 64.796875 \n",
       "z\n",
       "M 9.8125 72.90625 \n",
       "L 30.078125 72.90625 \n",
       "Q 51.265625 72.90625 61.171875 64.09375 \n",
       "Q 71.09375 55.28125 71.09375 36.53125 \n",
       "Q 71.09375 17.671875 61.125 8.828125 \n",
       "Q 51.171875 0 30.078125 0 \n",
       "L 9.8125 0 \n",
       "z\n",
       "\" id=\"BitstreamVeraSans-Roman-44\"/>\n",
       "    </defs>\n",
       "    <g transform=\"translate(28.6164566929 125.552701772)scale(0.18 -0.18)\">\n",
       "     <use xlink:href=\"#BitstreamVeraSans-Roman-44\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "  </g>\n",
       " </g>\n",
       " <defs>\n",
       "  <clipPath id=\"paf49570c8d\">\n",
       "   <rect height=\"170.078740157\" width=\"170.078740157\" x=\"7.2\" y=\"7.2\"/>\n",
       "  </clipPath>\n",
       " </defs>\n",
       "</svg>\n"
      ],
      "text/plain": [
       "<matplotlib.figure.Figure at 0x7feba0b8c080>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "pgm = daft.PGM([3, 3], origin=[-0.5, 0.5])\n",
    "add_node(pgm, 'A', 'A', 0, 2.5)\n",
    "add_node(pgm, 'B', 'B', 1, 2.5)\n",
    "add_node(pgm, 'C', 'C', 1, 1.5)\n",
    "add_node(pgm, 'D', 'D', 0, 1.5)\n",
    "add_node(pgm, 'E', 'E', 1.8, 2)\n",
    "add_edges(pgm, [\n",
    "        ('B', 'A'),\n",
    "        ('C', 'B'),\n",
    "        ('D', 'C'),\n",
    "        ('A', 'D')\n",
    "    ])\n",
    "pgm.render()\n",
    "save('graph_cycle_example')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "image/svg+xml": [
       "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"no\"?>\n",
       "<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\n",
       "  \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n",
       "<!-- Created with matplotlib (http://matplotlib.org/) -->\n",
       "<svg height=\"184pt\" version=\"1.1\" viewBox=\"0 0 184 184\" width=\"184pt\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n",
       " <defs>\n",
       "  <style type=\"text/css\">\n",
       "*{stroke-linecap:butt;stroke-linejoin:round;stroke-miterlimit:100000;}\n",
       "  </style>\n",
       " </defs>\n",
       " <g id=\"figure_1\">\n",
       "  <g id=\"patch_1\">\n",
       "   <path d=\"M 0 184.47874 \n",
       "L 184.47874 184.47874 \n",
       "L 184.47874 0 \n",
       "L 0 0 \n",
       "L 0 184.47874 \n",
       "z\n",
       "\" style=\"fill:none;\"/>\n",
       "  </g>\n",
       "  <g id=\"axes_1\">\n",
       "   <g id=\"patch_2\">\n",
       "    <path clip-path=\"url(#pa59528f878)\" d=\"M 46.885039 109.247244 \n",
       "C 51.39558 109.247244 55.721988 107.455187 58.911422 104.265753 \n",
       "C 62.100856 101.076319 63.892913 96.749911 63.892913 92.23937 \n",
       "C 63.892913 87.728829 62.100856 83.402421 58.911422 80.212987 \n",
       "C 55.721988 77.023553 51.39558 75.231496 46.885039 75.231496 \n",
       "C 42.374498 75.231496 38.04809 77.023553 34.858656 80.212987 \n",
       "C 31.669222 83.402421 29.877165 87.728829 29.877165 92.23937 \n",
       "C 29.877165 96.749911 31.669222 101.076319 34.858656 104.265753 \n",
       "C 38.04809 107.455187 42.374498 109.247244 46.885039 109.247244 \n",
       "L 46.885039 109.247244 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_3\">\n",
       "    <path clip-path=\"url(#pa59528f878)\" d=\"M 92.23937 137.593701 \n",
       "C 96.749911 137.593701 101.076319 135.801644 104.265753 132.61221 \n",
       "C 107.455187 129.422776 109.247244 125.096368 109.247244 120.585827 \n",
       "C 109.247244 116.075286 107.455187 111.748878 104.265753 108.559444 \n",
       "C 101.076319 105.37001 96.749911 103.577953 92.23937 103.577953 \n",
       "C 87.728829 103.577953 83.402421 105.37001 80.212987 108.559444 \n",
       "C 77.023553 111.748878 75.231496 116.075286 75.231496 120.585827 \n",
       "C 75.231496 125.096368 77.023553 129.422776 80.212987 132.61221 \n",
       "C 83.402421 135.801644 87.728829 137.593701 92.23937 137.593701 \n",
       "L 92.23937 137.593701 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_4\">\n",
       "    <path clip-path=\"url(#pa59528f878)\" d=\"M 92.23937 80.900787 \n",
       "C 96.749911 80.900787 101.076319 79.108731 104.265753 75.919296 \n",
       "C 107.455187 72.729862 109.247244 68.403454 109.247244 63.892913 \n",
       "C 109.247244 59.382372 107.455187 55.055964 104.265753 51.86653 \n",
       "C 101.076319 48.677096 96.749911 46.885039 92.23937 46.885039 \n",
       "C 87.728829 46.885039 83.402421 48.677096 80.212987 51.86653 \n",
       "C 77.023553 55.055964 75.231496 59.382372 75.231496 63.892913 \n",
       "C 75.231496 68.403454 77.023553 72.729862 80.212987 75.919296 \n",
       "C 83.402421 79.108731 87.728829 80.900787 92.23937 80.900787 \n",
       "L 92.23937 80.900787 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_5\">\n",
       "    <path clip-path=\"url(#pa59528f878)\" d=\"M 137.593701 109.247244 \n",
       "C 142.104242 109.247244 146.43065 107.455187 149.620084 104.265753 \n",
       "C 152.809518 101.076319 154.601575 96.749911 154.601575 92.23937 \n",
       "C 154.601575 87.728829 152.809518 83.402421 149.620084 80.212987 \n",
       "C 146.43065 77.023553 142.104242 75.231496 137.593701 75.231496 \n",
       "C 133.08316 75.231496 128.756752 77.023553 125.567318 80.212987 \n",
       "C 122.377884 83.402421 120.585827 87.728829 120.585827 92.23937 \n",
       "C 120.585827 96.749911 122.377884 101.076319 125.567318 104.265753 \n",
       "C 128.756752 107.455187 133.08316 109.247244 137.593701 109.247244 \n",
       "L 137.593701 109.247244 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"line2d_1\">\n",
       "    <path clip-path=\"url(#pa59528f878)\" d=\"M 61.307688 83.225215 \n",
       "L 77.816722 72.907069 \n",
       "\" style=\"fill:none;stroke:#000000;stroke-linecap:square;\"/>\n",
       "   </g>\n",
       "   <g id=\"line2d_2\">\n",
       "    <path clip-path=\"url(#pa59528f878)\" d=\"M 106.662018 72.907069 \n",
       "L 123.171052 83.225215 \n",
       "\" style=\"fill:none;stroke:#000000;stroke-linecap:square;\"/>\n",
       "   </g>\n",
       "   <g id=\"line2d_3\">\n",
       "    <path clip-path=\"url(#pa59528f878)\" d=\"M 106.662018 111.571672 \n",
       "L 123.171052 101.253525 \n",
       "\" style=\"fill:none;stroke:#000000;stroke-linecap:square;\"/>\n",
       "   </g>\n",
       "   <g id=\"line2d_4\">\n",
       "    <path clip-path=\"url(#pa59528f878)\" d=\"M 61.307688 101.253525 \n",
       "L 77.816722 111.571672 \n",
       "\" style=\"fill:none;stroke:#000000;stroke-linecap:square;\"/>\n",
       "   </g>\n",
       "   <g id=\"matplotlib.axis_1\"/>\n",
       "   <g id=\"matplotlib.axis_2\"/>\n",
       "   <g id=\"text_1\">\n",
       "    <!-- A -->\n",
       "    <defs>\n",
       "     <path d=\"M 34.1875 63.1875 \n",
       "L 20.796875 26.90625 \n",
       "L 47.609375 26.90625 \n",
       "z\n",
       "M 28.609375 72.90625 \n",
       "L 39.796875 72.90625 \n",
       "L 67.578125 0 \n",
       "L 57.328125 0 \n",
       "L 50.6875 18.703125 \n",
       "L 17.828125 18.703125 \n",
       "L 11.1875 0 \n",
       "L 0.78125 0 \n",
       "z\n",
       "\" id=\"BitstreamVeraSans-Roman-41\"/>\n",
       "    </defs>\n",
       "    <g transform=\"translate(40.7284768701 97.2062450787)scale(0.18 -0.18)\">\n",
       "     <use xlink:href=\"#BitstreamVeraSans-Roman-41\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"text_2\">\n",
       "    <!-- C -->\n",
       "    <defs>\n",
       "     <path d=\"M 64.40625 67.28125 \n",
       "L 64.40625 56.890625 \n",
       "Q 59.421875 61.53125 53.78125 63.8125 \n",
       "Q 48.140625 66.109375 41.796875 66.109375 \n",
       "Q 29.296875 66.109375 22.65625 58.46875 \n",
       "Q 16.015625 50.828125 16.015625 36.375 \n",
       "Q 16.015625 21.96875 22.65625 14.328125 \n",
       "Q 29.296875 6.6875 41.796875 6.6875 \n",
       "Q 48.140625 6.6875 53.78125 8.984375 \n",
       "Q 59.421875 11.28125 64.40625 15.921875 \n",
       "L 64.40625 5.609375 \n",
       "Q 59.234375 2.09375 53.4375 0.328125 \n",
       "Q 47.65625 -1.421875 41.21875 -1.421875 \n",
       "Q 24.65625 -1.421875 15.125 8.703125 \n",
       "Q 5.609375 18.84375 5.609375 36.375 \n",
       "Q 5.609375 53.953125 15.125 64.078125 \n",
       "Q 24.65625 74.21875 41.21875 74.21875 \n",
       "Q 47.75 74.21875 53.53125 72.484375 \n",
       "Q 59.328125 70.75 64.40625 67.28125 \n",
       "\" id=\"BitstreamVeraSans-Roman-43\"/>\n",
       "    </defs>\n",
       "    <g transform=\"translate(85.9548388287 125.552701772)scale(0.18 -0.18)\">\n",
       "     <use xlink:href=\"#BitstreamVeraSans-Roman-43\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"text_3\">\n",
       "    <!-- B -->\n",
       "    <defs>\n",
       "     <path d=\"M 19.671875 34.8125 \n",
       "L 19.671875 8.109375 \n",
       "L 35.5 8.109375 \n",
       "Q 43.453125 8.109375 47.28125 11.40625 \n",
       "Q 51.125 14.703125 51.125 21.484375 \n",
       "Q 51.125 28.328125 47.28125 31.5625 \n",
       "Q 43.453125 34.8125 35.5 34.8125 \n",
       "z\n",
       "M 19.671875 64.796875 \n",
       "L 19.671875 42.828125 \n",
       "L 34.28125 42.828125 \n",
       "Q 41.5 42.828125 45.03125 45.53125 \n",
       "Q 48.578125 48.25 48.578125 53.8125 \n",
       "Q 48.578125 59.328125 45.03125 62.0625 \n",
       "Q 41.5 64.796875 34.28125 64.796875 \n",
       "z\n",
       "M 9.8125 72.90625 \n",
       "L 35.015625 72.90625 \n",
       "Q 46.296875 72.90625 52.390625 68.21875 \n",
       "Q 58.5 63.53125 58.5 54.890625 \n",
       "Q 58.5 48.1875 55.375 44.234375 \n",
       "Q 52.25 40.28125 46.1875 39.3125 \n",
       "Q 53.46875 37.75 57.5 32.78125 \n",
       "Q 61.53125 27.828125 61.53125 20.40625 \n",
       "Q 61.53125 10.640625 54.890625 5.3125 \n",
       "Q 48.25 0 35.984375 0 \n",
       "L 9.8125 0 \n",
       "z\n",
       "\" id=\"BitstreamVeraSans-Roman-42\"/>\n",
       "    </defs>\n",
       "    <g transform=\"translate(86.0645263287 68.8597883858)scale(0.18 -0.18)\">\n",
       "     <use xlink:href=\"#BitstreamVeraSans-Roman-42\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"text_4\">\n",
       "    <!-- D -->\n",
       "    <defs>\n",
       "     <path d=\"M 19.671875 64.796875 \n",
       "L 19.671875 8.109375 \n",
       "L 31.59375 8.109375 \n",
       "Q 46.6875 8.109375 53.6875 14.9375 \n",
       "Q 60.6875 21.78125 60.6875 36.53125 \n",
       "Q 60.6875 51.171875 53.6875 57.984375 \n",
       "Q 46.6875 64.796875 31.59375 64.796875 \n",
       "z\n",
       "M 9.8125 72.90625 \n",
       "L 30.078125 72.90625 \n",
       "Q 51.265625 72.90625 61.171875 64.09375 \n",
       "Q 71.09375 55.28125 71.09375 36.53125 \n",
       "Q 71.09375 17.671875 61.125 8.828125 \n",
       "Q 51.171875 0 30.078125 0 \n",
       "L 9.8125 0 \n",
       "z\n",
       "\" id=\"BitstreamVeraSans-Roman-44\"/>\n",
       "    </defs>\n",
       "    <g transform=\"translate(130.663700787 97.2062450787)scale(0.18 -0.18)\">\n",
       "     <use xlink:href=\"#BitstreamVeraSans-Roman-44\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "  </g>\n",
       " </g>\n",
       " <defs>\n",
       "  <clipPath id=\"pa59528f878\">\n",
       "   <rect height=\"170.078740157\" width=\"170.078740157\" x=\"7.2\" y=\"7.2\"/>\n",
       "  </clipPath>\n",
       " </defs>\n",
       "</svg>\n"
      ],
      "text/plain": [
       "<matplotlib.figure.Figure at 0x7feb96cb7470>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "pgm = daft.PGM([3, 3], origin=[-0.5, 0.5], directed=False)\n",
    "add_node(pgm, 'A', 'A', 0.2, 2)\n",
    "add_node(pgm, 'B', 'B', 1, 2.5)\n",
    "add_node(pgm, 'C', 'C', 1, 1.5)\n",
    "add_node(pgm, 'D', 'D', 1.8, 2)\n",
    "add_edges(pgm, [\n",
    "        ('A', 'B'),\n",
    "        ('B', 'D'),\n",
    "        ('C', 'D'),\n",
    "        ('A', 'C')\n",
    "    ])\n",
    "pgm.render()\n",
    "save('maximal_clique')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {
    "collapsed": false,
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "image/svg+xml": [
       "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"no\"?>\n",
       "<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\n",
       "  \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n",
       "<!-- Created with matplotlib (http://matplotlib.org/) -->\n",
       "<svg height=\"127pt\" version=\"1.1\" viewBox=\"0 0 241 127\" width=\"241pt\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n",
       " <defs>\n",
       "  <style type=\"text/css\">\n",
       "*{stroke-linecap:butt;stroke-linejoin:round;stroke-miterlimit:100000;}\n",
       "  </style>\n",
       " </defs>\n",
       " <g id=\"figure_1\">\n",
       "  <g id=\"patch_1\">\n",
       "   <path d=\"M 0 127.785827 \n",
       "L 241.171654 127.785827 \n",
       "L 241.171654 0 \n",
       "L 0 0 \n",
       "L 0 127.785827 \n",
       "z\n",
       "\" style=\"fill:none;\"/>\n",
       "  </g>\n",
       "  <g id=\"axes_1\">\n",
       "   <g id=\"patch_2\">\n",
       "    <path clip-path=\"url(#pf2dbaf6b36)\" d=\"M 77.816722 54.878758 \n",
       "L 74.286178 55.17923 \n",
       "L 75.412947 53.376399 \n",
       "L 61.307688 44.560612 \n",
       "L 61.307688 44.560612 \n",
       "L 75.412947 53.376399 \n",
       "L 76.539716 51.573568 \n",
       "L 77.816722 54.878758 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_3\">\n",
       "    <path clip-path=\"url(#pf2dbaf6b36)\" d=\"M 106.662018 54.878758 \n",
       "L 107.939024 51.573568 \n",
       "L 109.065793 53.376399 \n",
       "L 123.171052 44.560612 \n",
       "L 123.171052 44.560612 \n",
       "L 109.065793 53.376399 \n",
       "L 110.192563 55.17923 \n",
       "L 106.662018 54.878758 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_4\">\n",
       "    <path clip-path=\"url(#pf2dbaf6b36)\" d=\"M 168.525383 54.878758 \n",
       "L 164.994839 55.17923 \n",
       "L 166.121608 53.376399 \n",
       "L 152.016349 44.560612 \n",
       "L 152.016349 44.560612 \n",
       "L 166.121608 53.376399 \n",
       "L 167.248378 51.573568 \n",
       "L 168.525383 54.878758 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_5\">\n",
       "    <path clip-path=\"url(#pf2dbaf6b36)\" d=\"M 92.23937 80.900787 \n",
       "C 96.749911 80.900787 101.076319 79.108731 104.265753 75.919296 \n",
       "C 107.455187 72.729862 109.247244 68.403454 109.247244 63.892913 \n",
       "C 109.247244 59.382372 107.455187 55.055964 104.265753 51.86653 \n",
       "C 101.076319 48.677096 96.749911 46.885039 92.23937 46.885039 \n",
       "C 87.728829 46.885039 83.402421 48.677096 80.212987 51.86653 \n",
       "C 77.023553 55.055964 75.231496 59.382372 75.231496 63.892913 \n",
       "C 75.231496 68.403454 77.023553 72.729862 80.212987 75.919296 \n",
       "C 83.402421 79.108731 87.728829 80.900787 92.23937 80.900787 \n",
       "L 92.23937 80.900787 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_6\">\n",
       "    <path clip-path=\"url(#pf2dbaf6b36)\" d=\"M 182.948031 80.900787 \n",
       "C 187.458572 80.900787 191.78498 79.108731 194.974415 75.919296 \n",
       "C 198.163849 72.729862 199.955906 68.403454 199.955906 63.892913 \n",
       "C 199.955906 59.382372 198.163849 55.055964 194.974415 51.86653 \n",
       "C 191.78498 48.677096 187.458572 46.885039 182.948031 46.885039 \n",
       "C 178.437491 46.885039 174.111083 48.677096 170.921648 51.86653 \n",
       "C 167.732214 55.055964 165.940157 59.382372 165.940157 63.892913 \n",
       "C 165.940157 68.403454 167.732214 72.729862 170.921648 75.919296 \n",
       "C 174.111083 79.108731 178.437491 80.900787 182.948031 80.900787 \n",
       "L 182.948031 80.900787 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_7\">\n",
       "    <path clip-path=\"url(#pf2dbaf6b36)\" d=\"M 46.885039 52.554331 \n",
       "C 51.39558 52.554331 55.721988 50.762274 58.911422 47.57284 \n",
       "C 62.100856 44.383406 63.892913 40.056998 63.892913 35.546457 \n",
       "C 63.892913 31.035916 62.100856 26.709508 58.911422 23.520074 \n",
       "C 55.721988 20.33064 51.39558 18.538583 46.885039 18.538583 \n",
       "C 42.374498 18.538583 38.04809 20.33064 34.858656 23.520074 \n",
       "C 31.669222 26.709508 29.877165 31.035916 29.877165 35.546457 \n",
       "C 29.877165 40.056998 31.669222 44.383406 34.858656 47.57284 \n",
       "C 38.04809 50.762274 42.374498 52.554331 46.885039 52.554331 \n",
       "L 46.885039 52.554331 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_8\">\n",
       "    <path clip-path=\"url(#pf2dbaf6b36)\" d=\"M 137.593701 52.554331 \n",
       "C 142.104242 52.554331 146.43065 50.762274 149.620084 47.57284 \n",
       "C 152.809518 44.383406 154.601575 40.056998 154.601575 35.546457 \n",
       "C 154.601575 31.035916 152.809518 26.709508 149.620084 23.520074 \n",
       "C 146.43065 20.33064 142.104242 18.538583 137.593701 18.538583 \n",
       "C 133.08316 18.538583 128.756752 20.33064 125.567318 23.520074 \n",
       "C 122.377884 26.709508 120.585827 31.035916 120.585827 35.546457 \n",
       "C 120.585827 40.056998 122.377884 44.383406 125.567318 47.57284 \n",
       "C 128.756752 50.762274 133.08316 52.554331 137.593701 52.554331 \n",
       "L 137.593701 52.554331 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"matplotlib.axis_1\"/>\n",
       "   <g id=\"matplotlib.axis_2\"/>\n",
       "   <g id=\"text_1\">\n",
       "    <!-- A -->\n",
       "    <defs>\n",
       "     <path d=\"M 34.1875 63.1875 \n",
       "L 20.796875 26.90625 \n",
       "L 47.609375 26.90625 \n",
       "z\n",
       "M 28.609375 72.90625 \n",
       "L 39.796875 72.90625 \n",
       "L 67.578125 0 \n",
       "L 57.328125 0 \n",
       "L 50.6875 18.703125 \n",
       "L 17.828125 18.703125 \n",
       "L 11.1875 0 \n",
       "L 0.78125 0 \n",
       "z\n",
       "\" id=\"BitstreamVeraSans-Roman-41\"/>\n",
       "    </defs>\n",
       "    <g transform=\"translate(86.0828075787 68.8597883858)scale(0.18 -0.18)\">\n",
       "     <use xlink:href=\"#BitstreamVeraSans-Roman-41\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"text_2\">\n",
       "    <!-- R -->\n",
       "    <defs>\n",
       "     <path d=\"M 44.390625 34.1875 \n",
       "Q 47.5625 33.109375 50.5625 29.59375 \n",
       "Q 53.5625 26.078125 56.59375 19.921875 \n",
       "L 66.609375 0 \n",
       "L 56 0 \n",
       "L 46.6875 18.703125 \n",
       "Q 43.0625 26.03125 39.671875 28.421875 \n",
       "Q 36.28125 30.8125 30.421875 30.8125 \n",
       "L 19.671875 30.8125 \n",
       "L 19.671875 0 \n",
       "L 9.8125 0 \n",
       "L 9.8125 72.90625 \n",
       "L 32.078125 72.90625 \n",
       "Q 44.578125 72.90625 50.734375 67.671875 \n",
       "Q 56.890625 62.453125 56.890625 51.90625 \n",
       "Q 56.890625 45.015625 53.6875 40.46875 \n",
       "Q 50.484375 35.9375 44.390625 34.1875 \n",
       "M 19.671875 64.796875 \n",
       "L 19.671875 38.921875 \n",
       "L 32.078125 38.921875 \n",
       "Q 39.203125 38.921875 42.84375 42.21875 \n",
       "Q 46.484375 45.515625 46.484375 51.90625 \n",
       "Q 46.484375 58.296875 42.84375 61.546875 \n",
       "Q 39.203125 64.796875 32.078125 64.796875 \n",
       "z\n",
       "\" id=\"BitstreamVeraSans-Roman-52\"/>\n",
       "    </defs>\n",
       "    <g transform=\"translate(176.694437746 68.8597883858)scale(0.18 -0.18)\">\n",
       "     <use xlink:href=\"#BitstreamVeraSans-Roman-52\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"text_3\">\n",
       "    <!-- B -->\n",
       "    <defs>\n",
       "     <path d=\"M 19.671875 34.8125 \n",
       "L 19.671875 8.109375 \n",
       "L 35.5 8.109375 \n",
       "Q 43.453125 8.109375 47.28125 11.40625 \n",
       "Q 51.125 14.703125 51.125 21.484375 \n",
       "Q 51.125 28.328125 47.28125 31.5625 \n",
       "Q 43.453125 34.8125 35.5 34.8125 \n",
       "z\n",
       "M 19.671875 64.796875 \n",
       "L 19.671875 42.828125 \n",
       "L 34.28125 42.828125 \n",
       "Q 41.5 42.828125 45.03125 45.53125 \n",
       "Q 48.578125 48.25 48.578125 53.8125 \n",
       "Q 48.578125 59.328125 45.03125 62.0625 \n",
       "Q 41.5 64.796875 34.28125 64.796875 \n",
       "z\n",
       "M 9.8125 72.90625 \n",
       "L 35.015625 72.90625 \n",
       "Q 46.296875 72.90625 52.390625 68.21875 \n",
       "Q 58.5 63.53125 58.5 54.890625 \n",
       "Q 58.5 48.1875 55.375 44.234375 \n",
       "Q 52.25 40.28125 46.1875 39.3125 \n",
       "Q 53.46875 37.75 57.5 32.78125 \n",
       "Q 61.53125 27.828125 61.53125 20.40625 \n",
       "Q 61.53125 10.640625 54.890625 5.3125 \n",
       "Q 48.25 0 35.984375 0 \n",
       "L 9.8125 0 \n",
       "z\n",
       "\" id=\"BitstreamVeraSans-Roman-42\"/>\n",
       "    </defs>\n",
       "    <g transform=\"translate(40.7101956201 40.5133316929)scale(0.18 -0.18)\">\n",
       "     <use xlink:href=\"#BitstreamVeraSans-Roman-42\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"text_4\">\n",
       "    <!-- E -->\n",
       "    <defs>\n",
       "     <path d=\"M 9.8125 72.90625 \n",
       "L 55.90625 72.90625 \n",
       "L 55.90625 64.59375 \n",
       "L 19.671875 64.59375 \n",
       "L 19.671875 43.015625 \n",
       "L 54.390625 43.015625 \n",
       "L 54.390625 34.71875 \n",
       "L 19.671875 34.71875 \n",
       "L 19.671875 8.296875 \n",
       "L 56.78125 8.296875 \n",
       "L 56.78125 0 \n",
       "L 9.8125 0 \n",
       "z\n",
       "\" id=\"BitstreamVeraSans-Roman-45\"/>\n",
       "    </defs>\n",
       "    <g transform=\"translate(131.906825787 40.5133316929)scale(0.18 -0.18)\">\n",
       "     <use xlink:href=\"#BitstreamVeraSans-Roman-45\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "  </g>\n",
       " </g>\n",
       " <defs>\n",
       "  <clipPath id=\"pf2dbaf6b36\">\n",
       "   <rect height=\"113.385826772\" width=\"226.771653543\" x=\"7.2\" y=\"7.2\"/>\n",
       "  </clipPath>\n",
       " </defs>\n",
       "</svg>\n"
      ],
      "text/plain": [
       "<matplotlib.figure.Figure at 0x7feb96e33f28>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "pgm = daft.PGM([4, 2], origin=[-0.5, 0.5])\n",
    "add_node(pgm, 'B', 'B', 0.2, 2)\n",
    "add_node(pgm, 'A', 'A', 1, 1.5)\n",
    "add_node(pgm, 'E', 'E', 1.8, 2)\n",
    "add_node(pgm, 'R', 'R', 2.6, 1.5)\n",
    "add_edges(pgm, [\n",
    "        ('B', 'A'),\n",
    "        ('E', 'A'),\n",
    "        ('E', 'R'),\n",
    "    ])\n",
    "pgm.render()\n",
    "save('simple_belief_net')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "image/svg+xml": [
       "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"no\"?>\n",
       "<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\n",
       "  \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n",
       "<!-- Created with matplotlib (http://matplotlib.org/) -->\n",
       "<svg height=\"127pt\" version=\"1.1\" viewBox=\"0 0 156 127\" width=\"156pt\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n",
       " <defs>\n",
       "  <style type=\"text/css\">\n",
       "*{stroke-linecap:butt;stroke-linejoin:round;stroke-miterlimit:100000;}\n",
       "  </style>\n",
       " </defs>\n",
       " <g id=\"figure_1\">\n",
       "  <g id=\"patch_1\">\n",
       "   <path d=\"M 0 127.785827 \n",
       "L 156.132283 127.785827 \n",
       "L 156.132283 0 \n",
       "L 0 0 \n",
       "L 0 127.785827 \n",
       "z\n",
       "\" style=\"fill:none;\"/>\n",
       "  </g>\n",
       "  <g id=\"axes_1\">\n",
       "   <g id=\"patch_2\">\n",
       "    <path clip-path=\"url(#p13bb389886)\" d=\"M 68.428346 49.152756 \n",
       "L 71.829921 50.144882 \n",
       "L 70.129134 51.420472 \n",
       "L 82.034646 67.294488 \n",
       "L 82.034646 67.294488 \n",
       "L 70.129134 51.420472 \n",
       "L 68.428346 52.696063 \n",
       "L 68.428346 49.152756 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_3\">\n",
       "    <path clip-path=\"url(#p13bb389886)\" d=\"M 116.050394 49.152756 \n",
       "L 116.050394 52.696063 \n",
       "L 114.349606 51.420472 \n",
       "L 102.444094 67.294488 \n",
       "L 102.444094 67.294488 \n",
       "L 114.349606 51.420472 \n",
       "L 112.648819 50.144882 \n",
       "L 116.050394 49.152756 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_4\">\n",
       "    <path clip-path=\"url(#p13bb389886)\" d=\"M 126.255118 52.554331 \n",
       "C 130.765659 52.554331 135.092067 50.762274 138.281501 47.57284 \n",
       "C 141.470935 44.383406 143.262992 40.056998 143.262992 35.546457 \n",
       "C 143.262992 31.035916 141.470935 26.709508 138.281501 23.520074 \n",
       "C 135.092067 20.33064 130.765659 18.538583 126.255118 18.538583 \n",
       "C 121.744577 18.538583 117.418169 20.33064 114.228735 23.520074 \n",
       "C 111.039301 26.709508 109.247244 31.035916 109.247244 35.546457 \n",
       "C 109.247244 40.056998 111.039301 44.383406 114.228735 47.57284 \n",
       "C 117.418169 50.762274 121.744577 52.554331 126.255118 52.554331 \n",
       "L 126.255118 52.554331 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_5\">\n",
       "    <path clip-path=\"url(#p13bb389886)\" d=\"M 92.23937 97.908661 \n",
       "C 96.749911 97.908661 101.076319 96.116605 104.265753 92.92717 \n",
       "C 107.455187 89.737736 109.247244 85.411328 109.247244 80.900787 \n",
       "C 109.247244 76.390246 107.455187 72.063838 104.265753 68.874404 \n",
       "C 101.076319 65.68497 96.749911 63.892913 92.23937 63.892913 \n",
       "C 87.728829 63.892913 83.402421 65.68497 80.212987 68.874404 \n",
       "C 77.023553 72.063838 75.231496 76.390246 75.231496 80.900787 \n",
       "C 75.231496 85.411328 77.023553 89.737736 80.212987 92.92717 \n",
       "C 83.402421 96.116605 87.728829 97.908661 92.23937 97.908661 \n",
       "L 92.23937 97.908661 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_6\">\n",
       "    <path clip-path=\"url(#p13bb389886)\" d=\"M 58.223622 52.554331 \n",
       "C 62.734163 52.554331 67.060571 50.762274 70.250005 47.57284 \n",
       "C 73.439439 44.383406 75.231496 40.056998 75.231496 35.546457 \n",
       "C 75.231496 31.035916 73.439439 26.709508 70.250005 23.520074 \n",
       "C 67.060571 20.33064 62.734163 18.538583 58.223622 18.538583 \n",
       "C 53.713081 18.538583 49.386673 20.33064 46.197239 23.520074 \n",
       "C 43.007805 26.709508 41.215748 31.035916 41.215748 35.546457 \n",
       "C 41.215748 40.056998 43.007805 44.383406 46.197239 47.57284 \n",
       "C 49.386673 50.762274 53.713081 52.554331 58.223622 52.554331 \n",
       "L 58.223622 52.554331 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"matplotlib.axis_1\"/>\n",
       "   <g id=\"matplotlib.axis_2\"/>\n",
       "   <g id=\"text_1\">\n",
       "    <!-- Y -->\n",
       "    <defs>\n",
       "     <path d=\"M -0.203125 72.90625 \n",
       "L 10.40625 72.90625 \n",
       "L 30.609375 42.921875 \n",
       "L 50.6875 72.90625 \n",
       "L 61.28125 72.90625 \n",
       "L 35.5 34.71875 \n",
       "L 35.5 0 \n",
       "L 25.59375 0 \n",
       "L 25.59375 34.71875 \n",
       "z\n",
       "\" id=\"BitstreamVeraSans-Roman-59\"/>\n",
       "    </defs>\n",
       "    <g transform=\"translate(120.75808686 40.5133316929)scale(0.18 -0.18)\">\n",
       "     <use xlink:href=\"#BitstreamVeraSans-Roman-59\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"text_2\">\n",
       "    <!-- Z -->\n",
       "    <defs>\n",
       "     <path d=\"M 5.609375 72.90625 \n",
       "L 62.890625 72.90625 \n",
       "L 62.890625 65.375 \n",
       "L 16.796875 8.296875 \n",
       "L 64.015625 8.296875 \n",
       "L 64.015625 0 \n",
       "L 4.5 0 \n",
       "L 4.5 7.515625 \n",
       "L 50.59375 64.59375 \n",
       "L 5.609375 64.59375 \n",
       "z\n",
       "\" id=\"BitstreamVeraSans-Roman-5a\"/>\n",
       "    </defs>\n",
       "    <g transform=\"translate(86.0743700787 85.8676624016)scale(0.18 -0.18)\">\n",
       "     <use xlink:href=\"#BitstreamVeraSans-Roman-5a\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"text_3\">\n",
       "    <!-- X -->\n",
       "    <defs>\n",
       "     <path d=\"M 6.296875 72.90625 \n",
       "L 16.890625 72.90625 \n",
       "L 35.015625 45.796875 \n",
       "L 53.21875 72.90625 \n",
       "L 63.8125 72.90625 \n",
       "L 40.375 37.890625 \n",
       "L 65.375 0 \n",
       "L 54.78125 0 \n",
       "L 34.28125 31 \n",
       "L 13.625 0 \n",
       "L 2.984375 0 \n",
       "L 29 38.921875 \n",
       "z\n",
       "\" id=\"BitstreamVeraSans-Roman-58\"/>\n",
       "    </defs>\n",
       "    <g transform=\"translate(52.0586220472 40.5133316929)scale(0.18 -0.18)\">\n",
       "     <use xlink:href=\"#BitstreamVeraSans-Roman-58\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "  </g>\n",
       " </g>\n",
       " <defs>\n",
       "  <clipPath id=\"p13bb389886\">\n",
       "   <rect height=\"113.385826772\" width=\"141.732283465\" x=\"7.2\" y=\"7.2\"/>\n",
       "  </clipPath>\n",
       " </defs>\n",
       "</svg>\n"
      ],
      "text/plain": [
       "<matplotlib.figure.Figure at 0x7feb96e33a20>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "pgm = daft.PGM([2.5, 2], origin=[-0.5, 0.5])\n",
    "add_node(pgm, 'X', 'X', 0.4, 2)\n",
    "add_node(pgm, 'Z', 'Z', 1, 1.2)\n",
    "add_node(pgm, 'Y', 'Y', 1.6, 2)\n",
    "add_edges(pgm, [\n",
    "        ('Z', 'X'),\n",
    "        ('Z', 'Y'),\n",
    "    ])\n",
    "pgm.render()\n",
    "save('bn_triple_00')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "image/svg+xml": [
       "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"no\"?>\n",
       "<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\n",
       "  \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n",
       "<!-- Created with matplotlib (http://matplotlib.org/) -->\n",
       "<svg height=\"127pt\" version=\"1.1\" viewBox=\"0 0 156 127\" width=\"156pt\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n",
       " <defs>\n",
       "  <style type=\"text/css\">\n",
       "*{stroke-linecap:butt;stroke-linejoin:round;stroke-miterlimit:100000;}\n",
       "  </style>\n",
       " </defs>\n",
       " <g id=\"figure_1\">\n",
       "  <g id=\"patch_1\">\n",
       "   <path d=\"M 0 127.785827 \n",
       "L 156.132283 127.785827 \n",
       "L 156.132283 0 \n",
       "L 0 0 \n",
       "L 0 127.785827 \n",
       "z\n",
       "\" style=\"fill:none;\"/>\n",
       "  </g>\n",
       "  <g id=\"axes_1\">\n",
       "   <g id=\"patch_2\">\n",
       "    <path clip-path=\"url(#p13bf769441)\" d=\"M 82.034646 67.294488 \n",
       "L 78.633071 66.302362 \n",
       "L 80.333858 65.026772 \n",
       "L 68.428346 49.152756 \n",
       "L 68.428346 49.152756 \n",
       "L 80.333858 65.026772 \n",
       "L 82.034646 63.751181 \n",
       "L 82.034646 67.294488 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_3\">\n",
       "    <path clip-path=\"url(#p13bf769441)\" d=\"M 116.050394 49.152756 \n",
       "L 116.050394 52.696063 \n",
       "L 114.349606 51.420472 \n",
       "L 102.444094 67.294488 \n",
       "L 102.444094 67.294488 \n",
       "L 114.349606 51.420472 \n",
       "L 112.648819 50.144882 \n",
       "L 116.050394 49.152756 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_4\">\n",
       "    <path clip-path=\"url(#p13bf769441)\" d=\"M 126.255118 52.554331 \n",
       "C 130.765659 52.554331 135.092067 50.762274 138.281501 47.57284 \n",
       "C 141.470935 44.383406 143.262992 40.056998 143.262992 35.546457 \n",
       "C 143.262992 31.035916 141.470935 26.709508 138.281501 23.520074 \n",
       "C 135.092067 20.33064 130.765659 18.538583 126.255118 18.538583 \n",
       "C 121.744577 18.538583 117.418169 20.33064 114.228735 23.520074 \n",
       "C 111.039301 26.709508 109.247244 31.035916 109.247244 35.546457 \n",
       "C 109.247244 40.056998 111.039301 44.383406 114.228735 47.57284 \n",
       "C 117.418169 50.762274 121.744577 52.554331 126.255118 52.554331 \n",
       "L 126.255118 52.554331 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_5\">\n",
       "    <path clip-path=\"url(#p13bf769441)\" d=\"M 92.23937 97.908661 \n",
       "C 96.749911 97.908661 101.076319 96.116605 104.265753 92.92717 \n",
       "C 107.455187 89.737736 109.247244 85.411328 109.247244 80.900787 \n",
       "C 109.247244 76.390246 107.455187 72.063838 104.265753 68.874404 \n",
       "C 101.076319 65.68497 96.749911 63.892913 92.23937 63.892913 \n",
       "C 87.728829 63.892913 83.402421 65.68497 80.212987 68.874404 \n",
       "C 77.023553 72.063838 75.231496 76.390246 75.231496 80.900787 \n",
       "C 75.231496 85.411328 77.023553 89.737736 80.212987 92.92717 \n",
       "C 83.402421 96.116605 87.728829 97.908661 92.23937 97.908661 \n",
       "L 92.23937 97.908661 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_6\">\n",
       "    <path clip-path=\"url(#p13bf769441)\" d=\"M 58.223622 52.554331 \n",
       "C 62.734163 52.554331 67.060571 50.762274 70.250005 47.57284 \n",
       "C 73.439439 44.383406 75.231496 40.056998 75.231496 35.546457 \n",
       "C 75.231496 31.035916 73.439439 26.709508 70.250005 23.520074 \n",
       "C 67.060571 20.33064 62.734163 18.538583 58.223622 18.538583 \n",
       "C 53.713081 18.538583 49.386673 20.33064 46.197239 23.520074 \n",
       "C 43.007805 26.709508 41.215748 31.035916 41.215748 35.546457 \n",
       "C 41.215748 40.056998 43.007805 44.383406 46.197239 47.57284 \n",
       "C 49.386673 50.762274 53.713081 52.554331 58.223622 52.554331 \n",
       "L 58.223622 52.554331 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"matplotlib.axis_1\"/>\n",
       "   <g id=\"matplotlib.axis_2\"/>\n",
       "   <g id=\"text_1\">\n",
       "    <!-- Y -->\n",
       "    <defs>\n",
       "     <path d=\"M -0.203125 72.90625 \n",
       "L 10.40625 72.90625 \n",
       "L 30.609375 42.921875 \n",
       "L 50.6875 72.90625 \n",
       "L 61.28125 72.90625 \n",
       "L 35.5 34.71875 \n",
       "L 35.5 0 \n",
       "L 25.59375 0 \n",
       "L 25.59375 34.71875 \n",
       "z\n",
       "\" id=\"BitstreamVeraSans-Roman-59\"/>\n",
       "    </defs>\n",
       "    <g transform=\"translate(120.75808686 40.5133316929)scale(0.18 -0.18)\">\n",
       "     <use xlink:href=\"#BitstreamVeraSans-Roman-59\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"text_2\">\n",
       "    <!-- Z -->\n",
       "    <defs>\n",
       "     <path d=\"M 5.609375 72.90625 \n",
       "L 62.890625 72.90625 \n",
       "L 62.890625 65.375 \n",
       "L 16.796875 8.296875 \n",
       "L 64.015625 8.296875 \n",
       "L 64.015625 0 \n",
       "L 4.5 0 \n",
       "L 4.5 7.515625 \n",
       "L 50.59375 64.59375 \n",
       "L 5.609375 64.59375 \n",
       "z\n",
       "\" id=\"BitstreamVeraSans-Roman-5a\"/>\n",
       "    </defs>\n",
       "    <g transform=\"translate(86.0743700787 85.8676624016)scale(0.18 -0.18)\">\n",
       "     <use xlink:href=\"#BitstreamVeraSans-Roman-5a\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"text_3\">\n",
       "    <!-- X -->\n",
       "    <defs>\n",
       "     <path d=\"M 6.296875 72.90625 \n",
       "L 16.890625 72.90625 \n",
       "L 35.015625 45.796875 \n",
       "L 53.21875 72.90625 \n",
       "L 63.8125 72.90625 \n",
       "L 40.375 37.890625 \n",
       "L 65.375 0 \n",
       "L 54.78125 0 \n",
       "L 34.28125 31 \n",
       "L 13.625 0 \n",
       "L 2.984375 0 \n",
       "L 29 38.921875 \n",
       "z\n",
       "\" id=\"BitstreamVeraSans-Roman-58\"/>\n",
       "    </defs>\n",
       "    <g transform=\"translate(52.0586220472 40.5133316929)scale(0.18 -0.18)\">\n",
       "     <use xlink:href=\"#BitstreamVeraSans-Roman-58\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "  </g>\n",
       " </g>\n",
       " <defs>\n",
       "  <clipPath id=\"p13bf769441\">\n",
       "   <rect height=\"113.385826772\" width=\"141.732283465\" x=\"7.2\" y=\"7.2\"/>\n",
       "  </clipPath>\n",
       " </defs>\n",
       "</svg>\n"
      ],
      "text/plain": [
       "<matplotlib.figure.Figure at 0x7feb96c9c898>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "pgm = daft.PGM([2.5, 2], origin=[-0.5, 0.5])\n",
    "add_node(pgm, 'X', 'X', 0.4, 2)\n",
    "add_node(pgm, 'Z', 'Z', 1, 1.2)\n",
    "add_node(pgm, 'Y', 'Y', 1.6, 2)\n",
    "add_edges(pgm, [\n",
    "        ('X', 'Z'),\n",
    "        ('Z', 'Y'),\n",
    "    ])\n",
    "pgm.render()\n",
    "save('bn_triple_01')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "image/svg+xml": [
       "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"no\"?>\n",
       "<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\n",
       "  \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n",
       "<!-- Created with matplotlib (http://matplotlib.org/) -->\n",
       "<svg height=\"127pt\" version=\"1.1\" viewBox=\"0 0 156 127\" width=\"156pt\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n",
       " <defs>\n",
       "  <style type=\"text/css\">\n",
       "*{stroke-linecap:butt;stroke-linejoin:round;stroke-miterlimit:100000;}\n",
       "  </style>\n",
       " </defs>\n",
       " <g id=\"figure_1\">\n",
       "  <g id=\"patch_1\">\n",
       "   <path d=\"M 0 127.785827 \n",
       "L 156.132283 127.785827 \n",
       "L 156.132283 0 \n",
       "L 0 0 \n",
       "L 0 127.785827 \n",
       "z\n",
       "\" style=\"fill:none;\"/>\n",
       "  </g>\n",
       "  <g id=\"axes_1\">\n",
       "   <g id=\"patch_2\">\n",
       "    <path clip-path=\"url(#pc9e06b56a1)\" d=\"M 82.034646 67.294488 \n",
       "L 78.633071 66.302362 \n",
       "L 80.333858 65.026772 \n",
       "L 68.428346 49.152756 \n",
       "L 68.428346 49.152756 \n",
       "L 80.333858 65.026772 \n",
       "L 82.034646 63.751181 \n",
       "L 82.034646 67.294488 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_3\">\n",
       "    <path clip-path=\"url(#pc9e06b56a1)\" d=\"M 102.444094 67.294488 \n",
       "L 102.444094 63.751181 \n",
       "L 104.144882 65.026772 \n",
       "L 116.050394 49.152756 \n",
       "L 116.050394 49.152756 \n",
       "L 104.144882 65.026772 \n",
       "L 105.845669 66.302362 \n",
       "L 102.444094 67.294488 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_4\">\n",
       "    <path clip-path=\"url(#pc9e06b56a1)\" d=\"M 126.255118 52.554331 \n",
       "C 130.765659 52.554331 135.092067 50.762274 138.281501 47.57284 \n",
       "C 141.470935 44.383406 143.262992 40.056998 143.262992 35.546457 \n",
       "C 143.262992 31.035916 141.470935 26.709508 138.281501 23.520074 \n",
       "C 135.092067 20.33064 130.765659 18.538583 126.255118 18.538583 \n",
       "C 121.744577 18.538583 117.418169 20.33064 114.228735 23.520074 \n",
       "C 111.039301 26.709508 109.247244 31.035916 109.247244 35.546457 \n",
       "C 109.247244 40.056998 111.039301 44.383406 114.228735 47.57284 \n",
       "C 117.418169 50.762274 121.744577 52.554331 126.255118 52.554331 \n",
       "L 126.255118 52.554331 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_5\">\n",
       "    <path clip-path=\"url(#pc9e06b56a1)\" d=\"M 92.23937 97.908661 \n",
       "C 96.749911 97.908661 101.076319 96.116605 104.265753 92.92717 \n",
       "C 107.455187 89.737736 109.247244 85.411328 109.247244 80.900787 \n",
       "C 109.247244 76.390246 107.455187 72.063838 104.265753 68.874404 \n",
       "C 101.076319 65.68497 96.749911 63.892913 92.23937 63.892913 \n",
       "C 87.728829 63.892913 83.402421 65.68497 80.212987 68.874404 \n",
       "C 77.023553 72.063838 75.231496 76.390246 75.231496 80.900787 \n",
       "C 75.231496 85.411328 77.023553 89.737736 80.212987 92.92717 \n",
       "C 83.402421 96.116605 87.728829 97.908661 92.23937 97.908661 \n",
       "L 92.23937 97.908661 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_6\">\n",
       "    <path clip-path=\"url(#pc9e06b56a1)\" d=\"M 58.223622 52.554331 \n",
       "C 62.734163 52.554331 67.060571 50.762274 70.250005 47.57284 \n",
       "C 73.439439 44.383406 75.231496 40.056998 75.231496 35.546457 \n",
       "C 75.231496 31.035916 73.439439 26.709508 70.250005 23.520074 \n",
       "C 67.060571 20.33064 62.734163 18.538583 58.223622 18.538583 \n",
       "C 53.713081 18.538583 49.386673 20.33064 46.197239 23.520074 \n",
       "C 43.007805 26.709508 41.215748 31.035916 41.215748 35.546457 \n",
       "C 41.215748 40.056998 43.007805 44.383406 46.197239 47.57284 \n",
       "C 49.386673 50.762274 53.713081 52.554331 58.223622 52.554331 \n",
       "L 58.223622 52.554331 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"matplotlib.axis_1\"/>\n",
       "   <g id=\"matplotlib.axis_2\"/>\n",
       "   <g id=\"text_1\">\n",
       "    <!-- Y -->\n",
       "    <defs>\n",
       "     <path d=\"M -0.203125 72.90625 \n",
       "L 10.40625 72.90625 \n",
       "L 30.609375 42.921875 \n",
       "L 50.6875 72.90625 \n",
       "L 61.28125 72.90625 \n",
       "L 35.5 34.71875 \n",
       "L 35.5 0 \n",
       "L 25.59375 0 \n",
       "L 25.59375 34.71875 \n",
       "z\n",
       "\" id=\"BitstreamVeraSans-Roman-59\"/>\n",
       "    </defs>\n",
       "    <g transform=\"translate(120.75808686 40.5133316929)scale(0.18 -0.18)\">\n",
       "     <use xlink:href=\"#BitstreamVeraSans-Roman-59\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"text_2\">\n",
       "    <!-- Z -->\n",
       "    <defs>\n",
       "     <path d=\"M 5.609375 72.90625 \n",
       "L 62.890625 72.90625 \n",
       "L 62.890625 65.375 \n",
       "L 16.796875 8.296875 \n",
       "L 64.015625 8.296875 \n",
       "L 64.015625 0 \n",
       "L 4.5 0 \n",
       "L 4.5 7.515625 \n",
       "L 50.59375 64.59375 \n",
       "L 5.609375 64.59375 \n",
       "z\n",
       "\" id=\"BitstreamVeraSans-Roman-5a\"/>\n",
       "    </defs>\n",
       "    <g transform=\"translate(86.0743700787 85.8676624016)scale(0.18 -0.18)\">\n",
       "     <use xlink:href=\"#BitstreamVeraSans-Roman-5a\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"text_3\">\n",
       "    <!-- X -->\n",
       "    <defs>\n",
       "     <path d=\"M 6.296875 72.90625 \n",
       "L 16.890625 72.90625 \n",
       "L 35.015625 45.796875 \n",
       "L 53.21875 72.90625 \n",
       "L 63.8125 72.90625 \n",
       "L 40.375 37.890625 \n",
       "L 65.375 0 \n",
       "L 54.78125 0 \n",
       "L 34.28125 31 \n",
       "L 13.625 0 \n",
       "L 2.984375 0 \n",
       "L 29 38.921875 \n",
       "z\n",
       "\" id=\"BitstreamVeraSans-Roman-58\"/>\n",
       "    </defs>\n",
       "    <g transform=\"translate(52.0586220472 40.5133316929)scale(0.18 -0.18)\">\n",
       "     <use xlink:href=\"#BitstreamVeraSans-Roman-58\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "  </g>\n",
       " </g>\n",
       " <defs>\n",
       "  <clipPath id=\"pc9e06b56a1\">\n",
       "   <rect height=\"113.385826772\" width=\"141.732283465\" x=\"7.2\" y=\"7.2\"/>\n",
       "  </clipPath>\n",
       " </defs>\n",
       "</svg>\n"
      ],
      "text/plain": [
       "<matplotlib.figure.Figure at 0x7feb96cc62e8>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "pgm = daft.PGM([2.5, 2], origin=[-0.5, 0.5])\n",
    "add_node(pgm, 'X', 'X', 0.4, 2)\n",
    "add_node(pgm, 'Z', 'Z', 1, 1.2)\n",
    "add_node(pgm, 'Y', 'Y', 1.6, 2)\n",
    "add_edges(pgm, [\n",
    "        ('X', 'Z'),\n",
    "        ('Y', 'Z'),\n",
    "    ])\n",
    "pgm.render()\n",
    "save('bn_triple_02')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "image/svg+xml": [
       "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"no\"?>\n",
       "<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\n",
       "  \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n",
       "<!-- Created with matplotlib (http://matplotlib.org/) -->\n",
       "<svg height=\"241pt\" version=\"1.1\" viewBox=\"0 0 184 241\" width=\"184pt\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n",
       " <defs>\n",
       "  <style type=\"text/css\">\n",
       "*{stroke-linecap:butt;stroke-linejoin:round;stroke-miterlimit:100000;}\n",
       "  </style>\n",
       " </defs>\n",
       " <g id=\"figure_1\">\n",
       "  <g id=\"patch_1\">\n",
       "   <path d=\"M 0 241.171654 \n",
       "L 184.47874 241.171654 \n",
       "L 184.47874 -0 \n",
       "L 0 -0 \n",
       "L 0 241.171654 \n",
       "z\n",
       "\" style=\"fill:none;\"/>\n",
       "  </g>\n",
       "  <g id=\"axes_1\">\n",
       "   <g id=\"patch_2\">\n",
       "    <path clip-path=\"url(#pf06e00ff12)\" d=\"M 58.223622 75.231496 \n",
       "L 56.097638 72.39685 \n",
       "L 58.223622 72.39685 \n",
       "L 58.223622 52.554331 \n",
       "L 58.223622 52.554331 \n",
       "L 58.223622 72.39685 \n",
       "L 60.349606 72.39685 \n",
       "L 58.223622 75.231496 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_3\">\n",
       "    <path clip-path=\"url(#pf06e00ff12)\" d=\"M 83.488891 134.348152 \n",
       "L 80.207461 133.011273 \n",
       "L 82.030478 131.917463 \n",
       "L 66.974101 106.823502 \n",
       "L 66.974101 106.823502 \n",
       "L 82.030478 131.917463 \n",
       "L 83.853494 130.823653 \n",
       "L 83.488891 134.348152 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_4\">\n",
       "    <path clip-path=\"url(#pf06e00ff12)\" d=\"M 100.989849 134.348152 \n",
       "L 100.625246 130.823653 \n",
       "L 102.448262 131.917463 \n",
       "L 117.504639 106.823502 \n",
       "L 117.504639 106.823502 \n",
       "L 102.448262 131.917463 \n",
       "L 104.271279 133.011273 \n",
       "L 100.989849 134.348152 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_5\">\n",
       "    <path clip-path=\"url(#pf06e00ff12)\" d=\"M 92.23937 188.617323 \n",
       "L 90.113386 185.782677 \n",
       "L 92.23937 185.782677 \n",
       "L 92.23937 165.940157 \n",
       "L 92.23937 165.940157 \n",
       "L 92.23937 185.782677 \n",
       "L 94.365354 185.782677 \n",
       "L 92.23937 188.617323 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_6\">\n",
       "    <path clip-path=\"url(#pf06e00ff12)\" d=\"M 58.223622 52.554331 \n",
       "C 62.734163 52.554331 67.060571 50.762274 70.250005 47.57284 \n",
       "C 73.439439 44.383406 75.231496 40.056998 75.231496 35.546457 \n",
       "C 75.231496 31.035916 73.439439 26.709508 70.250005 23.520074 \n",
       "C 67.060571 20.33064 62.734163 18.538583 58.223622 18.538583 \n",
       "C 53.713081 18.538583 49.386673 20.33064 46.197239 23.520074 \n",
       "C 43.007805 26.709508 41.215748 31.035916 41.215748 35.546457 \n",
       "C 41.215748 40.056998 43.007805 44.383406 46.197239 47.57284 \n",
       "C 49.386673 50.762274 53.713081 52.554331 58.223622 52.554331 \n",
       "L 58.223622 52.554331 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_7\">\n",
       "    <path clip-path=\"url(#pf06e00ff12)\" d=\"M 92.23937 165.940157 \n",
       "C 96.749911 165.940157 101.076319 164.148101 104.265753 160.958667 \n",
       "C 107.455187 157.769232 109.247244 153.442824 109.247244 148.932283 \n",
       "C 109.247244 144.421743 107.455187 140.095334 104.265753 136.9059 \n",
       "C 101.076319 133.716466 96.749911 131.924409 92.23937 131.924409 \n",
       "C 87.728829 131.924409 83.402421 133.716466 80.212987 136.9059 \n",
       "C 77.023553 140.095334 75.231496 144.421743 75.231496 148.932283 \n",
       "C 75.231496 153.442824 77.023553 157.769232 80.212987 160.958667 \n",
       "C 83.402421 164.148101 87.728829 165.940157 92.23937 165.940157 \n",
       "L 92.23937 165.940157 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_8\">\n",
       "    <path clip-path=\"url(#pf06e00ff12)\" d=\"M 58.223622 109.247244 \n",
       "C 62.734163 109.247244 67.060571 107.455187 70.250005 104.265753 \n",
       "C 73.439439 101.076319 75.231496 96.749911 75.231496 92.23937 \n",
       "C 75.231496 87.728829 73.439439 83.402421 70.250005 80.212987 \n",
       "C 67.060571 77.023553 62.734163 75.231496 58.223622 75.231496 \n",
       "C 53.713081 75.231496 49.386673 77.023553 46.197239 80.212987 \n",
       "C 43.007805 83.402421 41.215748 87.728829 41.215748 92.23937 \n",
       "C 41.215748 96.749911 43.007805 101.076319 46.197239 104.265753 \n",
       "C 49.386673 107.455187 53.713081 109.247244 58.223622 109.247244 \n",
       "L 58.223622 109.247244 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_9\">\n",
       "    <path clip-path=\"url(#pf06e00ff12)\" d=\"M 92.23937 222.633071 \n",
       "C 96.749911 222.633071 101.076319 220.841014 104.265753 217.65158 \n",
       "C 107.455187 214.462146 109.247244 210.135738 109.247244 205.625197 \n",
       "C 109.247244 201.114656 107.455187 196.788248 104.265753 193.598814 \n",
       "C 101.076319 190.40938 96.749911 188.617323 92.23937 188.617323 \n",
       "C 87.728829 188.617323 83.402421 190.40938 80.212987 193.598814 \n",
       "C 77.023553 196.788248 75.231496 201.114656 75.231496 205.625197 \n",
       "C 75.231496 210.135738 77.023553 214.462146 80.212987 217.65158 \n",
       "C 83.402421 220.841014 87.728829 222.633071 92.23937 222.633071 \n",
       "L 92.23937 222.633071 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_10\">\n",
       "    <path clip-path=\"url(#pf06e00ff12)\" d=\"M 126.255118 109.247244 \n",
       "C 130.765659 109.247244 135.092067 107.455187 138.281501 104.265753 \n",
       "C 141.470935 101.076319 143.262992 96.749911 143.262992 92.23937 \n",
       "C 143.262992 87.728829 141.470935 83.402421 138.281501 80.212987 \n",
       "C 135.092067 77.023553 130.765659 75.231496 126.255118 75.231496 \n",
       "C 121.744577 75.231496 117.418169 77.023553 114.228735 80.212987 \n",
       "C 111.039301 83.402421 109.247244 87.728829 109.247244 92.23937 \n",
       "C 109.247244 96.749911 111.039301 101.076319 114.228735 104.265753 \n",
       "C 117.418169 107.455187 121.744577 109.247244 126.255118 109.247244 \n",
       "L 126.255118 109.247244 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"matplotlib.axis_1\"/>\n",
       "   <g id=\"matplotlib.axis_2\"/>\n",
       "   <g id=\"text_1\">\n",
       "    <!-- A -->\n",
       "    <defs>\n",
       "     <path d=\"M 34.1875 63.1875 \n",
       "L 20.796875 26.90625 \n",
       "L 47.609375 26.90625 \n",
       "z\n",
       "M 28.609375 72.90625 \n",
       "L 39.796875 72.90625 \n",
       "L 67.578125 0 \n",
       "L 57.328125 0 \n",
       "L 50.6875 18.703125 \n",
       "L 17.828125 18.703125 \n",
       "L 11.1875 0 \n",
       "L 0.78125 0 \n",
       "z\n",
       "\" id=\"BitstreamVeraSans-Roman-41\"/>\n",
       "    </defs>\n",
       "    <g transform=\"translate(52.0670595472 40.5133316929)scale(0.18 -0.18)\">\n",
       "     <use xlink:href=\"#BitstreamVeraSans-Roman-41\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"text_2\">\n",
       "    <!-- C -->\n",
       "    <defs>\n",
       "     <path d=\"M 64.40625 67.28125 \n",
       "L 64.40625 56.890625 \n",
       "Q 59.421875 61.53125 53.78125 63.8125 \n",
       "Q 48.140625 66.109375 41.796875 66.109375 \n",
       "Q 29.296875 66.109375 22.65625 58.46875 \n",
       "Q 16.015625 50.828125 16.015625 36.375 \n",
       "Q 16.015625 21.96875 22.65625 14.328125 \n",
       "Q 29.296875 6.6875 41.796875 6.6875 \n",
       "Q 48.140625 6.6875 53.78125 8.984375 \n",
       "Q 59.421875 11.28125 64.40625 15.921875 \n",
       "L 64.40625 5.609375 \n",
       "Q 59.234375 2.09375 53.4375 0.328125 \n",
       "Q 47.65625 -1.421875 41.21875 -1.421875 \n",
       "Q 24.65625 -1.421875 15.125 8.703125 \n",
       "Q 5.609375 18.84375 5.609375 36.375 \n",
       "Q 5.609375 53.953125 15.125 64.078125 \n",
       "Q 24.65625 74.21875 41.21875 74.21875 \n",
       "Q 47.75 74.21875 53.53125 72.484375 \n",
       "Q 59.328125 70.75 64.40625 67.28125 \n",
       "\" id=\"BitstreamVeraSans-Roman-43\"/>\n",
       "    </defs>\n",
       "    <g transform=\"translate(85.9548388287 153.899158465)scale(0.18 -0.18)\">\n",
       "     <use xlink:href=\"#BitstreamVeraSans-Roman-43\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"text_3\">\n",
       "    <!-- B -->\n",
       "    <defs>\n",
       "     <path d=\"M 19.671875 34.8125 \n",
       "L 19.671875 8.109375 \n",
       "L 35.5 8.109375 \n",
       "Q 43.453125 8.109375 47.28125 11.40625 \n",
       "Q 51.125 14.703125 51.125 21.484375 \n",
       "Q 51.125 28.328125 47.28125 31.5625 \n",
       "Q 43.453125 34.8125 35.5 34.8125 \n",
       "z\n",
       "M 19.671875 64.796875 \n",
       "L 19.671875 42.828125 \n",
       "L 34.28125 42.828125 \n",
       "Q 41.5 42.828125 45.03125 45.53125 \n",
       "Q 48.578125 48.25 48.578125 53.8125 \n",
       "Q 48.578125 59.328125 45.03125 62.0625 \n",
       "Q 41.5 64.796875 34.28125 64.796875 \n",
       "z\n",
       "M 9.8125 72.90625 \n",
       "L 35.015625 72.90625 \n",
       "Q 46.296875 72.90625 52.390625 68.21875 \n",
       "Q 58.5 63.53125 58.5 54.890625 \n",
       "Q 58.5 48.1875 55.375 44.234375 \n",
       "Q 52.25 40.28125 46.1875 39.3125 \n",
       "Q 53.46875 37.75 57.5 32.78125 \n",
       "Q 61.53125 27.828125 61.53125 20.40625 \n",
       "Q 61.53125 10.640625 54.890625 5.3125 \n",
       "Q 48.25 0 35.984375 0 \n",
       "L 9.8125 0 \n",
       "z\n",
       "\" id=\"BitstreamVeraSans-Roman-42\"/>\n",
       "    </defs>\n",
       "    <g transform=\"translate(52.0487782972 97.2062450787)scale(0.18 -0.18)\">\n",
       "     <use xlink:href=\"#BitstreamVeraSans-Roman-42\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"text_4\">\n",
       "    <!-- E -->\n",
       "    <defs>\n",
       "     <path d=\"M 9.8125 72.90625 \n",
       "L 55.90625 72.90625 \n",
       "L 55.90625 64.59375 \n",
       "L 19.671875 64.59375 \n",
       "L 19.671875 43.015625 \n",
       "L 54.390625 43.015625 \n",
       "L 54.390625 34.71875 \n",
       "L 19.671875 34.71875 \n",
       "L 19.671875 8.296875 \n",
       "L 56.78125 8.296875 \n",
       "L 56.78125 0 \n",
       "L 9.8125 0 \n",
       "z\n",
       "\" id=\"BitstreamVeraSans-Roman-45\"/>\n",
       "    </defs>\n",
       "    <g transform=\"translate(86.5524950787 210.59207185)scale(0.18 -0.18)\">\n",
       "     <use xlink:href=\"#BitstreamVeraSans-Roman-45\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"text_5\">\n",
       "    <!-- D -->\n",
       "    <defs>\n",
       "     <path d=\"M 19.671875 64.796875 \n",
       "L 19.671875 8.109375 \n",
       "L 31.59375 8.109375 \n",
       "Q 46.6875 8.109375 53.6875 14.9375 \n",
       "Q 60.6875 21.78125 60.6875 36.53125 \n",
       "Q 60.6875 51.171875 53.6875 57.984375 \n",
       "Q 46.6875 64.796875 31.59375 64.796875 \n",
       "z\n",
       "M 9.8125 72.90625 \n",
       "L 30.078125 72.90625 \n",
       "Q 51.265625 72.90625 61.171875 64.09375 \n",
       "Q 71.09375 55.28125 71.09375 36.53125 \n",
       "Q 71.09375 17.671875 61.125 8.828125 \n",
       "Q 51.171875 0 30.078125 0 \n",
       "L 9.8125 0 \n",
       "z\n",
       "\" id=\"BitstreamVeraSans-Roman-44\"/>\n",
       "    </defs>\n",
       "    <g transform=\"translate(119.32511811 97.2062450787)scale(0.18 -0.18)\">\n",
       "     <use xlink:href=\"#BitstreamVeraSans-Roman-44\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "  </g>\n",
       " </g>\n",
       " <defs>\n",
       "  <clipPath id=\"pf06e00ff12\">\n",
       "   <rect height=\"226.771653543\" width=\"170.078740157\" x=\"7.2\" y=\"7.2\"/>\n",
       "  </clipPath>\n",
       " </defs>\n",
       "</svg>\n"
      ],
      "text/plain": [
       "<matplotlib.figure.Figure at 0x7feb96c495f8>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "pgm = daft.PGM([3, 4], origin=[-0.5, 0.5])\n",
    "add_node(pgm, 'A', 'A', 0.4, 4)\n",
    "add_node(pgm, 'B', 'B', 0.4, 3)\n",
    "add_node(pgm, 'C', 'C', 1, 2)\n",
    "add_node(pgm, 'D', 'D', 1.6, 3)\n",
    "add_node(pgm, 'E', 'E', 1, 1)\n",
    "add_edges(pgm, [\n",
    "        ('A', 'B'),\n",
    "        ('B', 'C'),\n",
    "        ('D', 'C'),\n",
    "        ('C', 'E')\n",
    "    ])\n",
    "pgm.render()\n",
    "save('collider_example')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "image/svg+xml": [
       "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"no\"?>\n",
       "<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\n",
       "  \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n",
       "<!-- Created with matplotlib (http://matplotlib.org/) -->\n",
       "<svg height=\"127pt\" version=\"1.1\" viewBox=\"0 0 156 127\" width=\"156pt\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n",
       " <defs>\n",
       "  <style type=\"text/css\">\n",
       "*{stroke-linecap:butt;stroke-linejoin:round;stroke-miterlimit:100000;}\n",
       "  </style>\n",
       " </defs>\n",
       " <g id=\"figure_1\">\n",
       "  <g id=\"patch_1\">\n",
       "   <path d=\"M 0 127.785827 \n",
       "L 156.132283 127.785827 \n",
       "L 156.132283 0 \n",
       "L 0 0 \n",
       "L 0 127.785827 \n",
       "z\n",
       "\" style=\"fill:none;\"/>\n",
       "  </g>\n",
       "  <g id=\"axes_1\">\n",
       "   <g id=\"patch_2\">\n",
       "    <path clip-path=\"url(#p8fc4e25be9)\" d=\"M 82.034646 67.294488 \n",
       "L 78.633071 66.302362 \n",
       "L 80.333858 65.026772 \n",
       "L 68.428346 49.152756 \n",
       "L 68.428346 49.152756 \n",
       "L 80.333858 65.026772 \n",
       "L 82.034646 63.751181 \n",
       "L 82.034646 67.294488 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_3\">\n",
       "    <path clip-path=\"url(#p8fc4e25be9)\" d=\"M 102.444094 67.294488 \n",
       "L 102.444094 63.751181 \n",
       "L 104.144882 65.026772 \n",
       "L 116.050394 49.152756 \n",
       "L 116.050394 49.152756 \n",
       "L 104.144882 65.026772 \n",
       "L 105.845669 66.302362 \n",
       "L 102.444094 67.294488 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_4\">\n",
       "    <path clip-path=\"url(#p8fc4e25be9)\" d=\"M 58.223622 52.554331 \n",
       "C 62.734163 52.554331 67.060571 50.762274 70.250005 47.57284 \n",
       "C 73.439439 44.383406 75.231496 40.056998 75.231496 35.546457 \n",
       "C 75.231496 31.035916 73.439439 26.709508 70.250005 23.520074 \n",
       "C 67.060571 20.33064 62.734163 18.538583 58.223622 18.538583 \n",
       "C 53.713081 18.538583 49.386673 20.33064 46.197239 23.520074 \n",
       "C 43.007805 26.709508 41.215748 31.035916 41.215748 35.546457 \n",
       "C 41.215748 40.056998 43.007805 44.383406 46.197239 47.57284 \n",
       "C 49.386673 50.762274 53.713081 52.554331 58.223622 52.554331 \n",
       "L 58.223622 52.554331 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_5\">\n",
       "    <path clip-path=\"url(#p8fc4e25be9)\" d=\"M 92.23937 97.908661 \n",
       "C 96.749911 97.908661 101.076319 96.116605 104.265753 92.92717 \n",
       "C 107.455187 89.737736 109.247244 85.411328 109.247244 80.900787 \n",
       "C 109.247244 76.390246 107.455187 72.063838 104.265753 68.874404 \n",
       "C 101.076319 65.68497 96.749911 63.892913 92.23937 63.892913 \n",
       "C 87.728829 63.892913 83.402421 65.68497 80.212987 68.874404 \n",
       "C 77.023553 72.063838 75.231496 76.390246 75.231496 80.900787 \n",
       "C 75.231496 85.411328 77.023553 89.737736 80.212987 92.92717 \n",
       "C 83.402421 96.116605 87.728829 97.908661 92.23937 97.908661 \n",
       "L 92.23937 97.908661 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_6\">\n",
       "    <path clip-path=\"url(#p8fc4e25be9)\" d=\"M 126.255118 52.554331 \n",
       "C 130.765659 52.554331 135.092067 50.762274 138.281501 47.57284 \n",
       "C 141.470935 44.383406 143.262992 40.056998 143.262992 35.546457 \n",
       "C 143.262992 31.035916 141.470935 26.709508 138.281501 23.520074 \n",
       "C 135.092067 20.33064 130.765659 18.538583 126.255118 18.538583 \n",
       "C 121.744577 18.538583 117.418169 20.33064 114.228735 23.520074 \n",
       "C 111.039301 26.709508 109.247244 31.035916 109.247244 35.546457 \n",
       "C 109.247244 40.056998 111.039301 44.383406 114.228735 47.57284 \n",
       "C 117.418169 50.762274 121.744577 52.554331 126.255118 52.554331 \n",
       "L 126.255118 52.554331 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"matplotlib.axis_1\"/>\n",
       "   <g id=\"matplotlib.axis_2\"/>\n",
       "   <g id=\"text_1\">\n",
       "    <!-- A -->\n",
       "    <defs>\n",
       "     <path d=\"M 34.1875 63.1875 \n",
       "L 20.796875 26.90625 \n",
       "L 47.609375 26.90625 \n",
       "z\n",
       "M 28.609375 72.90625 \n",
       "L 39.796875 72.90625 \n",
       "L 67.578125 0 \n",
       "L 57.328125 0 \n",
       "L 50.6875 18.703125 \n",
       "L 17.828125 18.703125 \n",
       "L 11.1875 0 \n",
       "L 0.78125 0 \n",
       "z\n",
       "\" id=\"BitstreamVeraSans-Roman-41\"/>\n",
       "    </defs>\n",
       "    <g transform=\"translate(52.0670595472 40.5133316929)scale(0.18 -0.18)\">\n",
       "     <use xlink:href=\"#BitstreamVeraSans-Roman-41\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"text_2\">\n",
       "    <!-- C -->\n",
       "    <defs>\n",
       "     <path d=\"M 64.40625 67.28125 \n",
       "L 64.40625 56.890625 \n",
       "Q 59.421875 61.53125 53.78125 63.8125 \n",
       "Q 48.140625 66.109375 41.796875 66.109375 \n",
       "Q 29.296875 66.109375 22.65625 58.46875 \n",
       "Q 16.015625 50.828125 16.015625 36.375 \n",
       "Q 16.015625 21.96875 22.65625 14.328125 \n",
       "Q 29.296875 6.6875 41.796875 6.6875 \n",
       "Q 48.140625 6.6875 53.78125 8.984375 \n",
       "Q 59.421875 11.28125 64.40625 15.921875 \n",
       "L 64.40625 5.609375 \n",
       "Q 59.234375 2.09375 53.4375 0.328125 \n",
       "Q 47.65625 -1.421875 41.21875 -1.421875 \n",
       "Q 24.65625 -1.421875 15.125 8.703125 \n",
       "Q 5.609375 18.84375 5.609375 36.375 \n",
       "Q 5.609375 53.953125 15.125 64.078125 \n",
       "Q 24.65625 74.21875 41.21875 74.21875 \n",
       "Q 47.75 74.21875 53.53125 72.484375 \n",
       "Q 59.328125 70.75 64.40625 67.28125 \n",
       "\" id=\"BitstreamVeraSans-Roman-43\"/>\n",
       "    </defs>\n",
       "    <g transform=\"translate(85.9548388287 85.8676624016)scale(0.18 -0.18)\">\n",
       "     <use xlink:href=\"#BitstreamVeraSans-Roman-43\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"text_3\">\n",
       "    <!-- B -->\n",
       "    <defs>\n",
       "     <path d=\"M 19.671875 34.8125 \n",
       "L 19.671875 8.109375 \n",
       "L 35.5 8.109375 \n",
       "Q 43.453125 8.109375 47.28125 11.40625 \n",
       "Q 51.125 14.703125 51.125 21.484375 \n",
       "Q 51.125 28.328125 47.28125 31.5625 \n",
       "Q 43.453125 34.8125 35.5 34.8125 \n",
       "z\n",
       "M 19.671875 64.796875 \n",
       "L 19.671875 42.828125 \n",
       "L 34.28125 42.828125 \n",
       "Q 41.5 42.828125 45.03125 45.53125 \n",
       "Q 48.578125 48.25 48.578125 53.8125 \n",
       "Q 48.578125 59.328125 45.03125 62.0625 \n",
       "Q 41.5 64.796875 34.28125 64.796875 \n",
       "z\n",
       "M 9.8125 72.90625 \n",
       "L 35.015625 72.90625 \n",
       "Q 46.296875 72.90625 52.390625 68.21875 \n",
       "Q 58.5 63.53125 58.5 54.890625 \n",
       "Q 58.5 48.1875 55.375 44.234375 \n",
       "Q 52.25 40.28125 46.1875 39.3125 \n",
       "Q 53.46875 37.75 57.5 32.78125 \n",
       "Q 61.53125 27.828125 61.53125 20.40625 \n",
       "Q 61.53125 10.640625 54.890625 5.3125 \n",
       "Q 48.25 0 35.984375 0 \n",
       "L 9.8125 0 \n",
       "z\n",
       "\" id=\"BitstreamVeraSans-Roman-42\"/>\n",
       "    </defs>\n",
       "    <g transform=\"translate(120.08027436 40.5133316929)scale(0.18 -0.18)\">\n",
       "     <use xlink:href=\"#BitstreamVeraSans-Roman-42\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "  </g>\n",
       " </g>\n",
       " <defs>\n",
       "  <clipPath id=\"p8fc4e25be9\">\n",
       "   <rect height=\"113.385826772\" width=\"141.732283465\" x=\"7.2\" y=\"7.2\"/>\n",
       "  </clipPath>\n",
       " </defs>\n",
       "</svg>\n"
      ],
      "text/plain": [
       "<matplotlib.figure.Figure at 0x7feb96cc6ba8>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "pgm = daft.PGM([2.5, 2], origin=[-0.5, 0.5])\n",
    "add_node(pgm, 'A', 'A', 0.4, 2)\n",
    "add_node(pgm, 'C', 'C', 1, 1.2)\n",
    "add_node(pgm, 'B', 'B', 1.6, 2)\n",
    "add_edges(pgm, [\n",
    "        ('A', 'C'),\n",
    "        ('B', 'C'),\n",
    "    ])\n",
    "pgm.render()\n",
    "save('bn_prop_00')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "image/svg+xml": [
       "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"no\"?>\n",
       "<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\n",
       "  \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n",
       "<!-- Created with matplotlib (http://matplotlib.org/) -->\n",
       "<svg height=\"184pt\" version=\"1.1\" viewBox=\"0 0 156 184\" width=\"156pt\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n",
       " <defs>\n",
       "  <style type=\"text/css\">\n",
       "*{stroke-linecap:butt;stroke-linejoin:round;stroke-miterlimit:100000;}\n",
       "  </style>\n",
       " </defs>\n",
       " <g id=\"figure_1\">\n",
       "  <g id=\"patch_1\">\n",
       "   <path d=\"M 0 184.47874 \n",
       "L 156.132283 184.47874 \n",
       "L 156.132283 0 \n",
       "L 0 0 \n",
       "L 0 184.47874 \n",
       "z\n",
       "\" style=\"fill:none;\"/>\n",
       "  </g>\n",
       "  <g id=\"axes_1\">\n",
       "   <g id=\"patch_2\">\n",
       "    <path clip-path=\"url(#p19b7d82c7d)\" d=\"M 82.034646 67.294488 \n",
       "L 78.633071 66.302362 \n",
       "L 80.333858 65.026772 \n",
       "L 68.428346 49.152756 \n",
       "L 68.428346 49.152756 \n",
       "L 80.333858 65.026772 \n",
       "L 82.034646 63.751181 \n",
       "L 82.034646 67.294488 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_3\">\n",
       "    <path clip-path=\"url(#p19b7d82c7d)\" d=\"M 102.444094 67.294488 \n",
       "L 102.444094 63.751181 \n",
       "L 104.144882 65.026772 \n",
       "L 116.050394 49.152756 \n",
       "L 116.050394 49.152756 \n",
       "L 104.144882 65.026772 \n",
       "L 105.845669 66.302362 \n",
       "L 102.444094 67.294488 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_4\">\n",
       "    <path clip-path=\"url(#p19b7d82c7d)\" d=\"M 58.223622 52.554331 \n",
       "C 62.734163 52.554331 67.060571 50.762274 70.250005 47.57284 \n",
       "C 73.439439 44.383406 75.231496 40.056998 75.231496 35.546457 \n",
       "C 75.231496 31.035916 73.439439 26.709508 70.250005 23.520074 \n",
       "C 67.060571 20.33064 62.734163 18.538583 58.223622 18.538583 \n",
       "C 53.713081 18.538583 49.386673 20.33064 46.197239 23.520074 \n",
       "C 43.007805 26.709508 41.215748 31.035916 41.215748 35.546457 \n",
       "C 41.215748 40.056998 43.007805 44.383406 46.197239 47.57284 \n",
       "C 49.386673 50.762274 53.713081 52.554331 58.223622 52.554331 \n",
       "L 58.223622 52.554331 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_5\">\n",
       "    <path clip-path=\"url(#p19b7d82c7d)\" d=\"M 92.23937 97.908661 \n",
       "C 96.749911 97.908661 101.076319 96.116605 104.265753 92.92717 \n",
       "C 107.455187 89.737736 109.247244 85.411328 109.247244 80.900787 \n",
       "C 109.247244 76.390246 107.455187 72.063838 104.265753 68.874404 \n",
       "C 101.076319 65.68497 96.749911 63.892913 92.23937 63.892913 \n",
       "C 87.728829 63.892913 83.402421 65.68497 80.212987 68.874404 \n",
       "C 77.023553 72.063838 75.231496 76.390246 75.231496 80.900787 \n",
       "C 75.231496 85.411328 77.023553 89.737736 80.212987 92.92717 \n",
       "C 83.402421 96.116605 87.728829 97.908661 92.23937 97.908661 \n",
       "L 92.23937 97.908661 \n",
       "z\n",
       "\" style=\"fill:none;opacity:0.25;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_6\">\n",
       "    <path clip-path=\"url(#p19b7d82c7d)\" d=\"M 126.255118 52.554331 \n",
       "C 130.765659 52.554331 135.092067 50.762274 138.281501 47.57284 \n",
       "C 141.470935 44.383406 143.262992 40.056998 143.262992 35.546457 \n",
       "C 143.262992 31.035916 141.470935 26.709508 138.281501 23.520074 \n",
       "C 135.092067 20.33064 130.765659 18.538583 126.255118 18.538583 \n",
       "C 121.744577 18.538583 117.418169 20.33064 114.228735 23.520074 \n",
       "C 111.039301 26.709508 109.247244 31.035916 109.247244 35.546457 \n",
       "C 109.247244 40.056998 111.039301 44.383406 114.228735 47.57284 \n",
       "C 117.418169 50.762274 121.744577 52.554331 126.255118 52.554331 \n",
       "L 126.255118 52.554331 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_7\">\n",
       "    <path clip-path=\"url(#p19b7d82c7d)\" d=\"M 126.255118 165.940157 \n",
       "C 130.765659 165.940157 135.092067 164.148101 138.281501 160.958667 \n",
       "C 141.470935 157.769232 143.262992 153.442824 143.262992 148.932283 \n",
       "C 143.262992 144.421743 141.470935 140.095334 138.281501 136.9059 \n",
       "C 135.092067 133.716466 130.765659 131.924409 126.255118 131.924409 \n",
       "C 121.744577 131.924409 117.418169 133.716466 114.228735 136.9059 \n",
       "C 111.039301 140.095334 109.247244 144.421743 109.247244 148.932283 \n",
       "C 109.247244 153.442824 111.039301 157.769232 114.228735 160.958667 \n",
       "C 117.418169 164.148101 121.744577 165.940157 126.255118 165.940157 \n",
       "L 126.255118 165.940157 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_8\">\n",
       "    <path clip-path=\"url(#p19b7d82c7d)\" d=\"M 58.223622 165.940157 \n",
       "C 62.734163 165.940157 67.060571 164.148101 70.250005 160.958667 \n",
       "C 73.439439 157.769232 75.231496 153.442824 75.231496 148.932283 \n",
       "C 75.231496 144.421743 73.439439 140.095334 70.250005 136.9059 \n",
       "C 67.060571 133.716466 62.734163 131.924409 58.223622 131.924409 \n",
       "C 53.713081 131.924409 49.386673 133.716466 46.197239 136.9059 \n",
       "C 43.007805 140.095334 41.215748 144.421743 41.215748 148.932283 \n",
       "C 41.215748 153.442824 43.007805 157.769232 46.197239 160.958667 \n",
       "C 49.386673 164.148101 53.713081 165.940157 58.223622 165.940157 \n",
       "L 58.223622 165.940157 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"matplotlib.axis_1\"/>\n",
       "   <g id=\"matplotlib.axis_2\"/>\n",
       "   <g id=\"text_1\">\n",
       "    <!-- A -->\n",
       "    <defs>\n",
       "     <path d=\"M 34.1875 63.1875 \n",
       "L 20.796875 26.90625 \n",
       "L 47.609375 26.90625 \n",
       "z\n",
       "M 28.609375 72.90625 \n",
       "L 39.796875 72.90625 \n",
       "L 67.578125 0 \n",
       "L 57.328125 0 \n",
       "L 50.6875 18.703125 \n",
       "L 17.828125 18.703125 \n",
       "L 11.1875 0 \n",
       "L 0.78125 0 \n",
       "z\n",
       "\" id=\"BitstreamVeraSans-Roman-41\"/>\n",
       "    </defs>\n",
       "    <g transform=\"translate(52.0670595472 40.5133316929)scale(0.18 -0.18)\">\n",
       "     <use xlink:href=\"#BitstreamVeraSans-Roman-41\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"text_2\">\n",
       "    <!-- C -->\n",
       "    <defs>\n",
       "     <path d=\"M 64.40625 67.28125 \n",
       "L 64.40625 56.890625 \n",
       "Q 59.421875 61.53125 53.78125 63.8125 \n",
       "Q 48.140625 66.109375 41.796875 66.109375 \n",
       "Q 29.296875 66.109375 22.65625 58.46875 \n",
       "Q 16.015625 50.828125 16.015625 36.375 \n",
       "Q 16.015625 21.96875 22.65625 14.328125 \n",
       "Q 29.296875 6.6875 41.796875 6.6875 \n",
       "Q 48.140625 6.6875 53.78125 8.984375 \n",
       "Q 59.421875 11.28125 64.40625 15.921875 \n",
       "L 64.40625 5.609375 \n",
       "Q 59.234375 2.09375 53.4375 0.328125 \n",
       "Q 47.65625 -1.421875 41.21875 -1.421875 \n",
       "Q 24.65625 -1.421875 15.125 8.703125 \n",
       "Q 5.609375 18.84375 5.609375 36.375 \n",
       "Q 5.609375 53.953125 15.125 64.078125 \n",
       "Q 24.65625 74.21875 41.21875 74.21875 \n",
       "Q 47.75 74.21875 53.53125 72.484375 \n",
       "Q 59.328125 70.75 64.40625 67.28125 \n",
       "\" id=\"BitstreamVeraSans-Roman-43\"/>\n",
       "    </defs>\n",
       "    <g style=\"opacity:0.25;\" transform=\"translate(85.9548388287 85.8676624016)scale(0.18 -0.18)\">\n",
       "     <use xlink:href=\"#BitstreamVeraSans-Roman-43\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"text_3\">\n",
       "    <!-- B -->\n",
       "    <defs>\n",
       "     <path d=\"M 19.671875 34.8125 \n",
       "L 19.671875 8.109375 \n",
       "L 35.5 8.109375 \n",
       "Q 43.453125 8.109375 47.28125 11.40625 \n",
       "Q 51.125 14.703125 51.125 21.484375 \n",
       "Q 51.125 28.328125 47.28125 31.5625 \n",
       "Q 43.453125 34.8125 35.5 34.8125 \n",
       "z\n",
       "M 19.671875 64.796875 \n",
       "L 19.671875 42.828125 \n",
       "L 34.28125 42.828125 \n",
       "Q 41.5 42.828125 45.03125 45.53125 \n",
       "Q 48.578125 48.25 48.578125 53.8125 \n",
       "Q 48.578125 59.328125 45.03125 62.0625 \n",
       "Q 41.5 64.796875 34.28125 64.796875 \n",
       "z\n",
       "M 9.8125 72.90625 \n",
       "L 35.015625 72.90625 \n",
       "Q 46.296875 72.90625 52.390625 68.21875 \n",
       "Q 58.5 63.53125 58.5 54.890625 \n",
       "Q 58.5 48.1875 55.375 44.234375 \n",
       "Q 52.25 40.28125 46.1875 39.3125 \n",
       "Q 53.46875 37.75 57.5 32.78125 \n",
       "Q 61.53125 27.828125 61.53125 20.40625 \n",
       "Q 61.53125 10.640625 54.890625 5.3125 \n",
       "Q 48.25 0 35.984375 0 \n",
       "L 9.8125 0 \n",
       "z\n",
       "\" id=\"BitstreamVeraSans-Roman-42\"/>\n",
       "    </defs>\n",
       "    <g transform=\"translate(120.08027436 40.5133316929)scale(0.18 -0.18)\">\n",
       "     <use xlink:href=\"#BitstreamVeraSans-Roman-42\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"text_4\">\n",
       "    <!-- B -->\n",
       "    <g transform=\"translate(120.08027436 153.899158465)scale(0.18 -0.18)\">\n",
       "     <use xlink:href=\"#BitstreamVeraSans-Roman-42\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"text_5\">\n",
       "    <!-- A -->\n",
       "    <g transform=\"translate(52.0670595472 153.899158465)scale(0.18 -0.18)\">\n",
       "     <use xlink:href=\"#BitstreamVeraSans-Roman-41\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "  </g>\n",
       " </g>\n",
       " <defs>\n",
       "  <clipPath id=\"p19b7d82c7d\">\n",
       "   <rect height=\"170.078740157\" width=\"141.732283465\" x=\"7.2\" y=\"7.2\"/>\n",
       "  </clipPath>\n",
       " </defs>\n",
       "</svg>\n"
      ],
      "text/plain": [
       "<matplotlib.figure.Figure at 0x7feb96bbc7b8>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "pgm = daft.PGM([2.5, 3], origin=[-0.5, 0.5])\n",
    "add_node(pgm, 'A', 'A', 0.4, 3)\n",
    "add_node(pgm, 'C', 'C', 1, 2.2,  plot_params={'alpha': 0.25}, label_params={'alpha': 0.25})\n",
    "add_node(pgm, 'B', 'B', 1.6, 3)\n",
    "add_node(pgm, 'A2', 'A', 0.4, 1)\n",
    "add_node(pgm, 'B2', 'B', 1.6, 1)\n",
    "add_edges(pgm, [\n",
    "        ('A', 'C'),\n",
    "        ('B', 'C'),\n",
    "    ])\n",
    "pgm.render()\n",
    "save('bn_prop_01')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "image/svg+xml": [
       "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"no\"?>\n",
       "<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\n",
       "  \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n",
       "<!-- Created with matplotlib (http://matplotlib.org/) -->\n",
       "<svg height=\"184pt\" version=\"1.1\" viewBox=\"0 0 156 184\" width=\"156pt\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n",
       " <defs>\n",
       "  <style type=\"text/css\">\n",
       "*{stroke-linecap:butt;stroke-linejoin:round;stroke-miterlimit:100000;}\n",
       "  </style>\n",
       " </defs>\n",
       " <g id=\"figure_1\">\n",
       "  <g id=\"patch_1\">\n",
       "   <path d=\"M 0 184.47874 \n",
       "L 156.132283 184.47874 \n",
       "L 156.132283 0 \n",
       "L 0 0 \n",
       "L 0 184.47874 \n",
       "z\n",
       "\" style=\"fill:none;\"/>\n",
       "  </g>\n",
       "  <g id=\"axes_1\">\n",
       "   <g id=\"patch_2\">\n",
       "    <path clip-path=\"url(#p777786a47d)\" d=\"M 82.034646 67.294488 \n",
       "L 78.633071 66.302362 \n",
       "L 80.333858 65.026772 \n",
       "L 68.428346 49.152756 \n",
       "L 68.428346 49.152756 \n",
       "L 80.333858 65.026772 \n",
       "L 82.034646 63.751181 \n",
       "L 82.034646 67.294488 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_3\">\n",
       "    <path clip-path=\"url(#p777786a47d)\" d=\"M 102.444094 67.294488 \n",
       "L 102.444094 63.751181 \n",
       "L 104.144882 65.026772 \n",
       "L 116.050394 49.152756 \n",
       "L 116.050394 49.152756 \n",
       "L 104.144882 65.026772 \n",
       "L 105.845669 66.302362 \n",
       "L 102.444094 67.294488 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_4\">\n",
       "    <path clip-path=\"url(#p777786a47d)\" d=\"M 109.247244 148.932283 \n",
       "L 106.412598 151.058268 \n",
       "L 106.412598 148.932283 \n",
       "L 75.231496 148.932283 \n",
       "L 75.231496 148.932283 \n",
       "L 106.412598 148.932283 \n",
       "L 106.412598 146.806299 \n",
       "L 109.247244 148.932283 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_5\">\n",
       "    <path clip-path=\"url(#p777786a47d)\" d=\"M 75.231496 148.932283 \n",
       "L 78.066142 146.806299 \n",
       "L 78.066142 148.932283 \n",
       "L 109.247244 148.932283 \n",
       "L 109.247244 148.932283 \n",
       "L 78.066142 148.932283 \n",
       "L 78.066142 151.058268 \n",
       "L 75.231496 148.932283 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_6\">\n",
       "    <path clip-path=\"url(#p777786a47d)\" d=\"M 58.223622 52.554331 \n",
       "C 62.734163 52.554331 67.060571 50.762274 70.250005 47.57284 \n",
       "C 73.439439 44.383406 75.231496 40.056998 75.231496 35.546457 \n",
       "C 75.231496 31.035916 73.439439 26.709508 70.250005 23.520074 \n",
       "C 67.060571 20.33064 62.734163 18.538583 58.223622 18.538583 \n",
       "C 53.713081 18.538583 49.386673 20.33064 46.197239 23.520074 \n",
       "C 43.007805 26.709508 41.215748 31.035916 41.215748 35.546457 \n",
       "C 41.215748 40.056998 43.007805 44.383406 46.197239 47.57284 \n",
       "C 49.386673 50.762274 53.713081 52.554331 58.223622 52.554331 \n",
       "L 58.223622 52.554331 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_7\">\n",
       "    <path clip-path=\"url(#p777786a47d)\" d=\"M 92.23937 97.908661 \n",
       "C 96.749911 97.908661 101.076319 96.116605 104.265753 92.92717 \n",
       "C 107.455187 89.737736 109.247244 85.411328 109.247244 80.900787 \n",
       "C 109.247244 76.390246 107.455187 72.063838 104.265753 68.874404 \n",
       "C 101.076319 65.68497 96.749911 63.892913 92.23937 63.892913 \n",
       "C 87.728829 63.892913 83.402421 65.68497 80.212987 68.874404 \n",
       "C 77.023553 72.063838 75.231496 76.390246 75.231496 80.900787 \n",
       "C 75.231496 85.411328 77.023553 89.737736 80.212987 92.92717 \n",
       "C 83.402421 96.116605 87.728829 97.908661 92.23937 97.908661 \n",
       "z\n",
       "\" style=\"fill:#386df9;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_8\">\n",
       "    <path clip-path=\"url(#p777786a47d)\" d=\"M 126.255118 52.554331 \n",
       "C 130.765659 52.554331 135.092067 50.762274 138.281501 47.57284 \n",
       "C 141.470935 44.383406 143.262992 40.056998 143.262992 35.546457 \n",
       "C 143.262992 31.035916 141.470935 26.709508 138.281501 23.520074 \n",
       "C 135.092067 20.33064 130.765659 18.538583 126.255118 18.538583 \n",
       "C 121.744577 18.538583 117.418169 20.33064 114.228735 23.520074 \n",
       "C 111.039301 26.709508 109.247244 31.035916 109.247244 35.546457 \n",
       "C 109.247244 40.056998 111.039301 44.383406 114.228735 47.57284 \n",
       "C 117.418169 50.762274 121.744577 52.554331 126.255118 52.554331 \n",
       "L 126.255118 52.554331 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_9\">\n",
       "    <path clip-path=\"url(#p777786a47d)\" d=\"M 126.255118 165.940157 \n",
       "C 130.765659 165.940157 135.092067 164.148101 138.281501 160.958667 \n",
       "C 141.470935 157.769232 143.262992 153.442824 143.262992 148.932283 \n",
       "C 143.262992 144.421743 141.470935 140.095334 138.281501 136.9059 \n",
       "C 135.092067 133.716466 130.765659 131.924409 126.255118 131.924409 \n",
       "C 121.744577 131.924409 117.418169 133.716466 114.228735 136.9059 \n",
       "C 111.039301 140.095334 109.247244 144.421743 109.247244 148.932283 \n",
       "C 109.247244 153.442824 111.039301 157.769232 114.228735 160.958667 \n",
       "C 117.418169 164.148101 121.744577 165.940157 126.255118 165.940157 \n",
       "L 126.255118 165.940157 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_10\">\n",
       "    <path clip-path=\"url(#p777786a47d)\" d=\"M 58.223622 165.940157 \n",
       "C 62.734163 165.940157 67.060571 164.148101 70.250005 160.958667 \n",
       "C 73.439439 157.769232 75.231496 153.442824 75.231496 148.932283 \n",
       "C 75.231496 144.421743 73.439439 140.095334 70.250005 136.9059 \n",
       "C 67.060571 133.716466 62.734163 131.924409 58.223622 131.924409 \n",
       "C 53.713081 131.924409 49.386673 133.716466 46.197239 136.9059 \n",
       "C 43.007805 140.095334 41.215748 144.421743 41.215748 148.932283 \n",
       "C 41.215748 153.442824 43.007805 157.769232 46.197239 160.958667 \n",
       "C 49.386673 164.148101 53.713081 165.940157 58.223622 165.940157 \n",
       "L 58.223622 165.940157 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"matplotlib.axis_1\"/>\n",
       "   <g id=\"matplotlib.axis_2\"/>\n",
       "   <g id=\"text_1\">\n",
       "    <!-- A -->\n",
       "    <defs>\n",
       "     <path d=\"M 34.1875 63.1875 \n",
       "L 20.796875 26.90625 \n",
       "L 47.609375 26.90625 \n",
       "z\n",
       "M 28.609375 72.90625 \n",
       "L 39.796875 72.90625 \n",
       "L 67.578125 0 \n",
       "L 57.328125 0 \n",
       "L 50.6875 18.703125 \n",
       "L 17.828125 18.703125 \n",
       "L 11.1875 0 \n",
       "L 0.78125 0 \n",
       "z\n",
       "\" id=\"BitstreamVeraSans-Roman-41\"/>\n",
       "    </defs>\n",
       "    <g transform=\"translate(52.0670595472 40.5133316929)scale(0.18 -0.18)\">\n",
       "     <use xlink:href=\"#BitstreamVeraSans-Roman-41\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"text_2\">\n",
       "    <!-- C -->\n",
       "    <defs>\n",
       "     <path d=\"M 64.40625 67.28125 \n",
       "L 64.40625 56.890625 \n",
       "Q 59.421875 61.53125 53.78125 63.8125 \n",
       "Q 48.140625 66.109375 41.796875 66.109375 \n",
       "Q 29.296875 66.109375 22.65625 58.46875 \n",
       "Q 16.015625 50.828125 16.015625 36.375 \n",
       "Q 16.015625 21.96875 22.65625 14.328125 \n",
       "Q 29.296875 6.6875 41.796875 6.6875 \n",
       "Q 48.140625 6.6875 53.78125 8.984375 \n",
       "Q 59.421875 11.28125 64.40625 15.921875 \n",
       "L 64.40625 5.609375 \n",
       "Q 59.234375 2.09375 53.4375 0.328125 \n",
       "Q 47.65625 -1.421875 41.21875 -1.421875 \n",
       "Q 24.65625 -1.421875 15.125 8.703125 \n",
       "Q 5.609375 18.84375 5.609375 36.375 \n",
       "Q 5.609375 53.953125 15.125 64.078125 \n",
       "Q 24.65625 74.21875 41.21875 74.21875 \n",
       "Q 47.75 74.21875 53.53125 72.484375 \n",
       "Q 59.328125 70.75 64.40625 67.28125 \n",
       "\" id=\"BitstreamVeraSans-Roman-43\"/>\n",
       "    </defs>\n",
       "    <g style=\"fill:#ffffff;\" transform=\"translate(85.9548388287 85.8676624016)scale(0.18 -0.18)\">\n",
       "     <use xlink:href=\"#BitstreamVeraSans-Roman-43\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"text_3\">\n",
       "    <!-- B -->\n",
       "    <defs>\n",
       "     <path d=\"M 19.671875 34.8125 \n",
       "L 19.671875 8.109375 \n",
       "L 35.5 8.109375 \n",
       "Q 43.453125 8.109375 47.28125 11.40625 \n",
       "Q 51.125 14.703125 51.125 21.484375 \n",
       "Q 51.125 28.328125 47.28125 31.5625 \n",
       "Q 43.453125 34.8125 35.5 34.8125 \n",
       "z\n",
       "M 19.671875 64.796875 \n",
       "L 19.671875 42.828125 \n",
       "L 34.28125 42.828125 \n",
       "Q 41.5 42.828125 45.03125 45.53125 \n",
       "Q 48.578125 48.25 48.578125 53.8125 \n",
       "Q 48.578125 59.328125 45.03125 62.0625 \n",
       "Q 41.5 64.796875 34.28125 64.796875 \n",
       "z\n",
       "M 9.8125 72.90625 \n",
       "L 35.015625 72.90625 \n",
       "Q 46.296875 72.90625 52.390625 68.21875 \n",
       "Q 58.5 63.53125 58.5 54.890625 \n",
       "Q 58.5 48.1875 55.375 44.234375 \n",
       "Q 52.25 40.28125 46.1875 39.3125 \n",
       "Q 53.46875 37.75 57.5 32.78125 \n",
       "Q 61.53125 27.828125 61.53125 20.40625 \n",
       "Q 61.53125 10.640625 54.890625 5.3125 \n",
       "Q 48.25 0 35.984375 0 \n",
       "L 9.8125 0 \n",
       "z\n",
       "\" id=\"BitstreamVeraSans-Roman-42\"/>\n",
       "    </defs>\n",
       "    <g transform=\"translate(120.08027436 40.5133316929)scale(0.18 -0.18)\">\n",
       "     <use xlink:href=\"#BitstreamVeraSans-Roman-42\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"text_4\">\n",
       "    <!-- B -->\n",
       "    <g transform=\"translate(120.08027436 153.899158465)scale(0.18 -0.18)\">\n",
       "     <use xlink:href=\"#BitstreamVeraSans-Roman-42\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"text_5\">\n",
       "    <!-- A -->\n",
       "    <g transform=\"translate(52.0670595472 153.899158465)scale(0.18 -0.18)\">\n",
       "     <use xlink:href=\"#BitstreamVeraSans-Roman-41\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "  </g>\n",
       " </g>\n",
       " <defs>\n",
       "  <clipPath id=\"p777786a47d\">\n",
       "   <rect height=\"170.078740157\" width=\"141.732283465\" x=\"7.2\" y=\"7.2\"/>\n",
       "  </clipPath>\n",
       " </defs>\n",
       "</svg>\n"
      ],
      "text/plain": [
       "<matplotlib.figure.Figure at 0x7feb96afb240>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "pgm = daft.PGM([2.5, 3], origin=[-0.5, 0.5])\n",
    "add_node(pgm, 'A', 'A', 0.4, 3)\n",
    "add_node(pgm, 'C', 'C', 1, 2.2,  plot_params={'facecolor': '#386DF9'}, label_params={'color': 'w'})\n",
    "add_node(pgm, 'B', 'B', 1.6, 3)\n",
    "add_node(pgm, 'A2', 'A', 0.4, 1)\n",
    "add_node(pgm, 'B2', 'B', 1.6, 1)\n",
    "add_edges(pgm, [\n",
    "        ('A', 'C'),\n",
    "        ('B', 'C'),\n",
    "        ('A2', 'B2'),\n",
    "        ('B2', 'A2')\n",
    "    ])\n",
    "pgm.render()\n",
    "save('bn_prop_02')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "image/svg+xml": [
       "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"no\"?>\n",
       "<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\n",
       "  \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n",
       "<!-- Created with matplotlib (http://matplotlib.org/) -->\n",
       "<svg height=\"241pt\" version=\"1.1\" viewBox=\"0 0 156 241\" width=\"156pt\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n",
       " <defs>\n",
       "  <style type=\"text/css\">\n",
       "*{stroke-linecap:butt;stroke-linejoin:round;stroke-miterlimit:100000;}\n",
       "  </style>\n",
       " </defs>\n",
       " <g id=\"figure_1\">\n",
       "  <g id=\"patch_1\">\n",
       "   <path d=\"M 0 241.171654 \n",
       "L 156.132283 241.171654 \n",
       "L 156.132283 -0 \n",
       "L 0 -0 \n",
       "L 0 241.171654 \n",
       "z\n",
       "\" style=\"fill:none;\"/>\n",
       "  </g>\n",
       "  <g id=\"axes_1\">\n",
       "   <g id=\"patch_2\">\n",
       "    <path clip-path=\"url(#p7969ab8267)\" d=\"M 82.034646 67.294488 \n",
       "L 78.633071 66.302362 \n",
       "L 80.333858 65.026772 \n",
       "L 68.428346 49.152756 \n",
       "L 68.428346 49.152756 \n",
       "L 80.333858 65.026772 \n",
       "L 82.034646 63.751181 \n",
       "L 82.034646 67.294488 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_3\">\n",
       "    <path clip-path=\"url(#p7969ab8267)\" d=\"M 102.444094 67.294488 \n",
       "L 102.444094 63.751181 \n",
       "L 104.144882 65.026772 \n",
       "L 116.050394 49.152756 \n",
       "L 116.050394 49.152756 \n",
       "L 104.144882 65.026772 \n",
       "L 105.845669 66.302362 \n",
       "L 102.444094 67.294488 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_4\">\n",
       "    <path clip-path=\"url(#p7969ab8267)\" d=\"M 92.23937 120.585827 \n",
       "L 90.113386 117.751181 \n",
       "L 92.23937 117.751181 \n",
       "L 92.23937 97.908661 \n",
       "L 92.23937 97.908661 \n",
       "L 92.23937 117.751181 \n",
       "L 94.365354 117.751181 \n",
       "L 92.23937 120.585827 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_5\">\n",
       "    <path clip-path=\"url(#p7969ab8267)\" d=\"M 109.247244 205.625197 \n",
       "L 106.412598 207.751181 \n",
       "L 106.412598 205.625197 \n",
       "L 75.231496 205.625197 \n",
       "L 75.231496 205.625197 \n",
       "L 106.412598 205.625197 \n",
       "L 106.412598 203.499213 \n",
       "L 109.247244 205.625197 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_6\">\n",
       "    <path clip-path=\"url(#p7969ab8267)\" d=\"M 75.231496 205.625197 \n",
       "L 78.066142 203.499213 \n",
       "L 78.066142 205.625197 \n",
       "L 109.247244 205.625197 \n",
       "L 109.247244 205.625197 \n",
       "L 78.066142 205.625197 \n",
       "L 78.066142 207.751181 \n",
       "L 75.231496 205.625197 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_7\">\n",
       "    <path clip-path=\"url(#p7969ab8267)\" d=\"M 92.23937 97.908661 \n",
       "C 96.749911 97.908661 101.076319 96.116605 104.265753 92.92717 \n",
       "C 107.455187 89.737736 109.247244 85.411328 109.247244 80.900787 \n",
       "C 109.247244 76.390246 107.455187 72.063838 104.265753 68.874404 \n",
       "C 101.076319 65.68497 96.749911 63.892913 92.23937 63.892913 \n",
       "C 87.728829 63.892913 83.402421 65.68497 80.212987 68.874404 \n",
       "C 77.023553 72.063838 75.231496 76.390246 75.231496 80.900787 \n",
       "C 75.231496 85.411328 77.023553 89.737736 80.212987 92.92717 \n",
       "C 83.402421 96.116605 87.728829 97.908661 92.23937 97.908661 \n",
       "z\n",
       "\" style=\"fill:#386df9;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_8\">\n",
       "    <path clip-path=\"url(#p7969ab8267)\" d=\"M 92.23937 154.601575 \n",
       "C 96.749911 154.601575 101.076319 152.809518 104.265753 149.620084 \n",
       "C 107.455187 146.43065 109.247244 142.104242 109.247244 137.593701 \n",
       "C 109.247244 133.08316 107.455187 128.756752 104.265753 125.567318 \n",
       "C 101.076319 122.377884 96.749911 120.585827 92.23937 120.585827 \n",
       "C 87.728829 120.585827 83.402421 122.377884 80.212987 125.567318 \n",
       "C 77.023553 128.756752 75.231496 133.08316 75.231496 137.593701 \n",
       "C 75.231496 142.104242 77.023553 146.43065 80.212987 149.620084 \n",
       "C 83.402421 152.809518 87.728829 154.601575 92.23937 154.601575 \n",
       "L 92.23937 154.601575 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_9\">\n",
       "    <path clip-path=\"url(#p7969ab8267)\" d=\"M 126.255118 52.554331 \n",
       "C 130.765659 52.554331 135.092067 50.762274 138.281501 47.57284 \n",
       "C 141.470935 44.383406 143.262992 40.056998 143.262992 35.546457 \n",
       "C 143.262992 31.035916 141.470935 26.709508 138.281501 23.520074 \n",
       "C 135.092067 20.33064 130.765659 18.538583 126.255118 18.538583 \n",
       "C 121.744577 18.538583 117.418169 20.33064 114.228735 23.520074 \n",
       "C 111.039301 26.709508 109.247244 31.035916 109.247244 35.546457 \n",
       "C 109.247244 40.056998 111.039301 44.383406 114.228735 47.57284 \n",
       "C 117.418169 50.762274 121.744577 52.554331 126.255118 52.554331 \n",
       "L 126.255118 52.554331 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_10\">\n",
       "    <path clip-path=\"url(#p7969ab8267)\" d=\"M 126.255118 222.633071 \n",
       "C 130.765659 222.633071 135.092067 220.841014 138.281501 217.65158 \n",
       "C 141.470935 214.462146 143.262992 210.135738 143.262992 205.625197 \n",
       "C 143.262992 201.114656 141.470935 196.788248 138.281501 193.598814 \n",
       "C 135.092067 190.40938 130.765659 188.617323 126.255118 188.617323 \n",
       "C 121.744577 188.617323 117.418169 190.40938 114.228735 193.598814 \n",
       "C 111.039301 196.788248 109.247244 201.114656 109.247244 205.625197 \n",
       "C 109.247244 210.135738 111.039301 214.462146 114.228735 217.65158 \n",
       "C 117.418169 220.841014 121.744577 222.633071 126.255118 222.633071 \n",
       "L 126.255118 222.633071 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_11\">\n",
       "    <path clip-path=\"url(#p7969ab8267)\" d=\"M 58.223622 222.633071 \n",
       "C 62.734163 222.633071 67.060571 220.841014 70.250005 217.65158 \n",
       "C 73.439439 214.462146 75.231496 210.135738 75.231496 205.625197 \n",
       "C 75.231496 201.114656 73.439439 196.788248 70.250005 193.598814 \n",
       "C 67.060571 190.40938 62.734163 188.617323 58.223622 188.617323 \n",
       "C 53.713081 188.617323 49.386673 190.40938 46.197239 193.598814 \n",
       "C 43.007805 196.788248 41.215748 201.114656 41.215748 205.625197 \n",
       "C 41.215748 210.135738 43.007805 214.462146 46.197239 217.65158 \n",
       "C 49.386673 220.841014 53.713081 222.633071 58.223622 222.633071 \n",
       "L 58.223622 222.633071 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_12\">\n",
       "    <path clip-path=\"url(#p7969ab8267)\" d=\"M 58.223622 52.554331 \n",
       "C 62.734163 52.554331 67.060571 50.762274 70.250005 47.57284 \n",
       "C 73.439439 44.383406 75.231496 40.056998 75.231496 35.546457 \n",
       "C 75.231496 31.035916 73.439439 26.709508 70.250005 23.520074 \n",
       "C 67.060571 20.33064 62.734163 18.538583 58.223622 18.538583 \n",
       "C 53.713081 18.538583 49.386673 20.33064 46.197239 23.520074 \n",
       "C 43.007805 26.709508 41.215748 31.035916 41.215748 35.546457 \n",
       "C 41.215748 40.056998 43.007805 44.383406 46.197239 47.57284 \n",
       "C 49.386673 50.762274 53.713081 52.554331 58.223622 52.554331 \n",
       "L 58.223622 52.554331 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"matplotlib.axis_1\"/>\n",
       "   <g id=\"matplotlib.axis_2\"/>\n",
       "   <g id=\"text_1\">\n",
       "    <!-- C -->\n",
       "    <defs>\n",
       "     <path d=\"M 64.40625 67.28125 \n",
       "L 64.40625 56.890625 \n",
       "Q 59.421875 61.53125 53.78125 63.8125 \n",
       "Q 48.140625 66.109375 41.796875 66.109375 \n",
       "Q 29.296875 66.109375 22.65625 58.46875 \n",
       "Q 16.015625 50.828125 16.015625 36.375 \n",
       "Q 16.015625 21.96875 22.65625 14.328125 \n",
       "Q 29.296875 6.6875 41.796875 6.6875 \n",
       "Q 48.140625 6.6875 53.78125 8.984375 \n",
       "Q 59.421875 11.28125 64.40625 15.921875 \n",
       "L 64.40625 5.609375 \n",
       "Q 59.234375 2.09375 53.4375 0.328125 \n",
       "Q 47.65625 -1.421875 41.21875 -1.421875 \n",
       "Q 24.65625 -1.421875 15.125 8.703125 \n",
       "Q 5.609375 18.84375 5.609375 36.375 \n",
       "Q 5.609375 53.953125 15.125 64.078125 \n",
       "Q 24.65625 74.21875 41.21875 74.21875 \n",
       "Q 47.75 74.21875 53.53125 72.484375 \n",
       "Q 59.328125 70.75 64.40625 67.28125 \n",
       "\" id=\"BitstreamVeraSans-Roman-43\"/>\n",
       "    </defs>\n",
       "    <g style=\"fill:#ffffff;\" transform=\"translate(85.9548388287 85.8676624016)scale(0.18 -0.18)\">\n",
       "     <use xlink:href=\"#BitstreamVeraSans-Roman-43\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"text_2\">\n",
       "    <!-- D -->\n",
       "    <defs>\n",
       "     <path d=\"M 19.671875 64.796875 \n",
       "L 19.671875 8.109375 \n",
       "L 31.59375 8.109375 \n",
       "Q 46.6875 8.109375 53.6875 14.9375 \n",
       "Q 60.6875 21.78125 60.6875 36.53125 \n",
       "Q 60.6875 51.171875 53.6875 57.984375 \n",
       "Q 46.6875 64.796875 31.59375 64.796875 \n",
       "z\n",
       "M 9.8125 72.90625 \n",
       "L 30.078125 72.90625 \n",
       "Q 51.265625 72.90625 61.171875 64.09375 \n",
       "Q 71.09375 55.28125 71.09375 36.53125 \n",
       "Q 71.09375 17.671875 61.125 8.828125 \n",
       "Q 51.171875 0 30.078125 0 \n",
       "L 9.8125 0 \n",
       "z\n",
       "\" id=\"BitstreamVeraSans-Roman-44\"/>\n",
       "    </defs>\n",
       "    <g transform=\"translate(85.3093700787 142.560575787)scale(0.18 -0.18)\">\n",
       "     <use xlink:href=\"#BitstreamVeraSans-Roman-44\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"text_3\">\n",
       "    <!-- B -->\n",
       "    <defs>\n",
       "     <path d=\"M 19.671875 34.8125 \n",
       "L 19.671875 8.109375 \n",
       "L 35.5 8.109375 \n",
       "Q 43.453125 8.109375 47.28125 11.40625 \n",
       "Q 51.125 14.703125 51.125 21.484375 \n",
       "Q 51.125 28.328125 47.28125 31.5625 \n",
       "Q 43.453125 34.8125 35.5 34.8125 \n",
       "z\n",
       "M 19.671875 64.796875 \n",
       "L 19.671875 42.828125 \n",
       "L 34.28125 42.828125 \n",
       "Q 41.5 42.828125 45.03125 45.53125 \n",
       "Q 48.578125 48.25 48.578125 53.8125 \n",
       "Q 48.578125 59.328125 45.03125 62.0625 \n",
       "Q 41.5 64.796875 34.28125 64.796875 \n",
       "z\n",
       "M 9.8125 72.90625 \n",
       "L 35.015625 72.90625 \n",
       "Q 46.296875 72.90625 52.390625 68.21875 \n",
       "Q 58.5 63.53125 58.5 54.890625 \n",
       "Q 58.5 48.1875 55.375 44.234375 \n",
       "Q 52.25 40.28125 46.1875 39.3125 \n",
       "Q 53.46875 37.75 57.5 32.78125 \n",
       "Q 61.53125 27.828125 61.53125 20.40625 \n",
       "Q 61.53125 10.640625 54.890625 5.3125 \n",
       "Q 48.25 0 35.984375 0 \n",
       "L 9.8125 0 \n",
       "z\n",
       "\" id=\"BitstreamVeraSans-Roman-42\"/>\n",
       "    </defs>\n",
       "    <g transform=\"translate(120.08027436 40.5133316929)scale(0.18 -0.18)\">\n",
       "     <use xlink:href=\"#BitstreamVeraSans-Roman-42\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"text_4\">\n",
       "    <!-- B -->\n",
       "    <g transform=\"translate(120.08027436 210.59207185)scale(0.18 -0.18)\">\n",
       "     <use xlink:href=\"#BitstreamVeraSans-Roman-42\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"text_5\">\n",
       "    <!-- A -->\n",
       "    <defs>\n",
       "     <path d=\"M 34.1875 63.1875 \n",
       "L 20.796875 26.90625 \n",
       "L 47.609375 26.90625 \n",
       "z\n",
       "M 28.609375 72.90625 \n",
       "L 39.796875 72.90625 \n",
       "L 67.578125 0 \n",
       "L 57.328125 0 \n",
       "L 50.6875 18.703125 \n",
       "L 17.828125 18.703125 \n",
       "L 11.1875 0 \n",
       "L 0.78125 0 \n",
       "z\n",
       "\" id=\"BitstreamVeraSans-Roman-41\"/>\n",
       "    </defs>\n",
       "    <g transform=\"translate(52.0670595472 210.59207185)scale(0.18 -0.18)\">\n",
       "     <use xlink:href=\"#BitstreamVeraSans-Roman-41\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"text_6\">\n",
       "    <!-- A -->\n",
       "    <g transform=\"translate(52.0670595472 40.5133316929)scale(0.18 -0.18)\">\n",
       "     <use xlink:href=\"#BitstreamVeraSans-Roman-41\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "  </g>\n",
       " </g>\n",
       " <defs>\n",
       "  <clipPath id=\"p7969ab8267\">\n",
       "   <rect height=\"226.771653543\" width=\"141.732283465\" x=\"7.2\" y=\"7.2\"/>\n",
       "  </clipPath>\n",
       " </defs>\n",
       "</svg>\n"
      ],
      "text/plain": [
       "<matplotlib.figure.Figure at 0x7feb96afbf98>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "pgm = daft.PGM([2.5, 4], origin=[-0.5, 0.5])\n",
    "add_node(pgm, 'A', 'A', 0.4, 4)\n",
    "add_node(pgm, 'C', 'C', 1, 3.2,  plot_params={'facecolor': '#386DF9'}, label_params={'color': 'w'})\n",
    "add_node(pgm, 'B', 'B', 1.6, 4)\n",
    "add_node(pgm, 'D', 'D', 1, 2.2)\n",
    "add_node(pgm, 'A2', 'A', 0.4, 1)\n",
    "add_node(pgm, 'B2', 'B', 1.6, 1)\n",
    "add_edges(pgm, [\n",
    "        ('A', 'C'),\n",
    "        ('B', 'C'),\n",
    "        ('C', 'D'),\n",
    "        ('A2', 'B2'),\n",
    "        ('B2', 'A2')\n",
    "    ])\n",
    "pgm.render()\n",
    "save('bn_prop_03')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "image/svg+xml": [
       "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"no\"?>\n",
       "<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\n",
       "  \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n",
       "<!-- Created with matplotlib (http://matplotlib.org/) -->\n",
       "<svg height=\"127pt\" version=\"1.1\" viewBox=\"0 0 156 127\" width=\"156pt\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n",
       " <defs>\n",
       "  <style type=\"text/css\">\n",
       "*{stroke-linecap:butt;stroke-linejoin:round;stroke-miterlimit:100000;}\n",
       "  </style>\n",
       " </defs>\n",
       " <g id=\"figure_1\">\n",
       "  <g id=\"patch_1\">\n",
       "   <path d=\"M 0 127.785827 \n",
       "L 156.132283 127.785827 \n",
       "L 156.132283 0 \n",
       "L 0 0 \n",
       "L 0 127.785827 \n",
       "z\n",
       "\" style=\"fill:none;\"/>\n",
       "  </g>\n",
       "  <g id=\"axes_1\">\n",
       "   <g id=\"patch_2\">\n",
       "    <path clip-path=\"url(#p25a56234f0)\" d=\"M 68.428346 49.152756 \n",
       "L 71.829921 50.144882 \n",
       "L 70.129134 51.420472 \n",
       "L 82.034646 67.294488 \n",
       "L 82.034646 67.294488 \n",
       "L 70.129134 51.420472 \n",
       "L 68.428346 52.696063 \n",
       "L 68.428346 49.152756 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_3\">\n",
       "    <path clip-path=\"url(#p25a56234f0)\" d=\"M 116.050394 49.152756 \n",
       "L 116.050394 52.696063 \n",
       "L 114.349606 51.420472 \n",
       "L 102.444094 67.294488 \n",
       "L 102.444094 67.294488 \n",
       "L 114.349606 51.420472 \n",
       "L 112.648819 50.144882 \n",
       "L 116.050394 49.152756 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_4\">\n",
       "    <path clip-path=\"url(#p25a56234f0)\" d=\"M 58.223622 52.554331 \n",
       "C 62.734163 52.554331 67.060571 50.762274 70.250005 47.57284 \n",
       "C 73.439439 44.383406 75.231496 40.056998 75.231496 35.546457 \n",
       "C 75.231496 31.035916 73.439439 26.709508 70.250005 23.520074 \n",
       "C 67.060571 20.33064 62.734163 18.538583 58.223622 18.538583 \n",
       "C 53.713081 18.538583 49.386673 20.33064 46.197239 23.520074 \n",
       "C 43.007805 26.709508 41.215748 31.035916 41.215748 35.546457 \n",
       "C 41.215748 40.056998 43.007805 44.383406 46.197239 47.57284 \n",
       "C 49.386673 50.762274 53.713081 52.554331 58.223622 52.554331 \n",
       "L 58.223622 52.554331 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_5\">\n",
       "    <path clip-path=\"url(#p25a56234f0)\" d=\"M 92.23937 97.908661 \n",
       "C 96.749911 97.908661 101.076319 96.116605 104.265753 92.92717 \n",
       "C 107.455187 89.737736 109.247244 85.411328 109.247244 80.900787 \n",
       "C 109.247244 76.390246 107.455187 72.063838 104.265753 68.874404 \n",
       "C 101.076319 65.68497 96.749911 63.892913 92.23937 63.892913 \n",
       "C 87.728829 63.892913 83.402421 65.68497 80.212987 68.874404 \n",
       "C 77.023553 72.063838 75.231496 76.390246 75.231496 80.900787 \n",
       "C 75.231496 85.411328 77.023553 89.737736 80.212987 92.92717 \n",
       "C 83.402421 96.116605 87.728829 97.908661 92.23937 97.908661 \n",
       "L 92.23937 97.908661 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_6\">\n",
       "    <path clip-path=\"url(#p25a56234f0)\" d=\"M 126.255118 52.554331 \n",
       "C 130.765659 52.554331 135.092067 50.762274 138.281501 47.57284 \n",
       "C 141.470935 44.383406 143.262992 40.056998 143.262992 35.546457 \n",
       "C 143.262992 31.035916 141.470935 26.709508 138.281501 23.520074 \n",
       "C 135.092067 20.33064 130.765659 18.538583 126.255118 18.538583 \n",
       "C 121.744577 18.538583 117.418169 20.33064 114.228735 23.520074 \n",
       "C 111.039301 26.709508 109.247244 31.035916 109.247244 35.546457 \n",
       "C 109.247244 40.056998 111.039301 44.383406 114.228735 47.57284 \n",
       "C 117.418169 50.762274 121.744577 52.554331 126.255118 52.554331 \n",
       "L 126.255118 52.554331 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"matplotlib.axis_1\"/>\n",
       "   <g id=\"matplotlib.axis_2\"/>\n",
       "   <g id=\"text_1\">\n",
       "    <!-- A -->\n",
       "    <defs>\n",
       "     <path d=\"M 34.1875 63.1875 \n",
       "L 20.796875 26.90625 \n",
       "L 47.609375 26.90625 \n",
       "z\n",
       "M 28.609375 72.90625 \n",
       "L 39.796875 72.90625 \n",
       "L 67.578125 0 \n",
       "L 57.328125 0 \n",
       "L 50.6875 18.703125 \n",
       "L 17.828125 18.703125 \n",
       "L 11.1875 0 \n",
       "L 0.78125 0 \n",
       "z\n",
       "\" id=\"BitstreamVeraSans-Roman-41\"/>\n",
       "    </defs>\n",
       "    <g transform=\"translate(52.0670595472 40.5133316929)scale(0.18 -0.18)\">\n",
       "     <use xlink:href=\"#BitstreamVeraSans-Roman-41\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"text_2\">\n",
       "    <!-- C -->\n",
       "    <defs>\n",
       "     <path d=\"M 64.40625 67.28125 \n",
       "L 64.40625 56.890625 \n",
       "Q 59.421875 61.53125 53.78125 63.8125 \n",
       "Q 48.140625 66.109375 41.796875 66.109375 \n",
       "Q 29.296875 66.109375 22.65625 58.46875 \n",
       "Q 16.015625 50.828125 16.015625 36.375 \n",
       "Q 16.015625 21.96875 22.65625 14.328125 \n",
       "Q 29.296875 6.6875 41.796875 6.6875 \n",
       "Q 48.140625 6.6875 53.78125 8.984375 \n",
       "Q 59.421875 11.28125 64.40625 15.921875 \n",
       "L 64.40625 5.609375 \n",
       "Q 59.234375 2.09375 53.4375 0.328125 \n",
       "Q 47.65625 -1.421875 41.21875 -1.421875 \n",
       "Q 24.65625 -1.421875 15.125 8.703125 \n",
       "Q 5.609375 18.84375 5.609375 36.375 \n",
       "Q 5.609375 53.953125 15.125 64.078125 \n",
       "Q 24.65625 74.21875 41.21875 74.21875 \n",
       "Q 47.75 74.21875 53.53125 72.484375 \n",
       "Q 59.328125 70.75 64.40625 67.28125 \n",
       "\" id=\"BitstreamVeraSans-Roman-43\"/>\n",
       "    </defs>\n",
       "    <g transform=\"translate(85.9548388287 85.8676624016)scale(0.18 -0.18)\">\n",
       "     <use xlink:href=\"#BitstreamVeraSans-Roman-43\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"text_3\">\n",
       "    <!-- B -->\n",
       "    <defs>\n",
       "     <path d=\"M 19.671875 34.8125 \n",
       "L 19.671875 8.109375 \n",
       "L 35.5 8.109375 \n",
       "Q 43.453125 8.109375 47.28125 11.40625 \n",
       "Q 51.125 14.703125 51.125 21.484375 \n",
       "Q 51.125 28.328125 47.28125 31.5625 \n",
       "Q 43.453125 34.8125 35.5 34.8125 \n",
       "z\n",
       "M 19.671875 64.796875 \n",
       "L 19.671875 42.828125 \n",
       "L 34.28125 42.828125 \n",
       "Q 41.5 42.828125 45.03125 45.53125 \n",
       "Q 48.578125 48.25 48.578125 53.8125 \n",
       "Q 48.578125 59.328125 45.03125 62.0625 \n",
       "Q 41.5 64.796875 34.28125 64.796875 \n",
       "z\n",
       "M 9.8125 72.90625 \n",
       "L 35.015625 72.90625 \n",
       "Q 46.296875 72.90625 52.390625 68.21875 \n",
       "Q 58.5 63.53125 58.5 54.890625 \n",
       "Q 58.5 48.1875 55.375 44.234375 \n",
       "Q 52.25 40.28125 46.1875 39.3125 \n",
       "Q 53.46875 37.75 57.5 32.78125 \n",
       "Q 61.53125 27.828125 61.53125 20.40625 \n",
       "Q 61.53125 10.640625 54.890625 5.3125 \n",
       "Q 48.25 0 35.984375 0 \n",
       "L 9.8125 0 \n",
       "z\n",
       "\" id=\"BitstreamVeraSans-Roman-42\"/>\n",
       "    </defs>\n",
       "    <g transform=\"translate(120.08027436 40.5133316929)scale(0.18 -0.18)\">\n",
       "     <use xlink:href=\"#BitstreamVeraSans-Roman-42\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "  </g>\n",
       " </g>\n",
       " <defs>\n",
       "  <clipPath id=\"p25a56234f0\">\n",
       "   <rect height=\"113.385826772\" width=\"141.732283465\" x=\"7.2\" y=\"7.2\"/>\n",
       "  </clipPath>\n",
       " </defs>\n",
       "</svg>\n"
      ],
      "text/plain": [
       "<matplotlib.figure.Figure at 0x7feb96d5dc88>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "pgm = daft.PGM([2.5, 2], origin=[-0.5, 0.5])\n",
    "add_node(pgm, 'A', 'A', 0.4, 2)\n",
    "add_node(pgm, 'C', 'C', 1, 1.2)\n",
    "add_node(pgm, 'B', 'B', 1.6, 2)\n",
    "add_edges(pgm, [\n",
    "        ('C', 'A'),\n",
    "        ('C', 'B'),\n",
    "    ])\n",
    "pgm.render()\n",
    "save('bn_prop_04')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "image/svg+xml": [
       "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"no\"?>\n",
       "<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\n",
       "  \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n",
       "<!-- Created with matplotlib (http://matplotlib.org/) -->\n",
       "<svg height=\"184pt\" version=\"1.1\" viewBox=\"0 0 156 184\" width=\"156pt\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n",
       " <defs>\n",
       "  <style type=\"text/css\">\n",
       "*{stroke-linecap:butt;stroke-linejoin:round;stroke-miterlimit:100000;}\n",
       "  </style>\n",
       " </defs>\n",
       " <g id=\"figure_1\">\n",
       "  <g id=\"patch_1\">\n",
       "   <path d=\"M 0 184.47874 \n",
       "L 156.132283 184.47874 \n",
       "L 156.132283 0 \n",
       "L 0 0 \n",
       "L 0 184.47874 \n",
       "z\n",
       "\" style=\"fill:none;\"/>\n",
       "  </g>\n",
       "  <g id=\"axes_1\">\n",
       "   <g id=\"patch_2\">\n",
       "    <path clip-path=\"url(#pe4a5b6deb6)\" d=\"M 68.428346 49.152756 \n",
       "L 71.829921 50.144882 \n",
       "L 70.129134 51.420472 \n",
       "L 82.034646 67.294488 \n",
       "L 82.034646 67.294488 \n",
       "L 70.129134 51.420472 \n",
       "L 68.428346 52.696063 \n",
       "L 68.428346 49.152756 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_3\">\n",
       "    <path clip-path=\"url(#pe4a5b6deb6)\" d=\"M 116.050394 49.152756 \n",
       "L 116.050394 52.696063 \n",
       "L 114.349606 51.420472 \n",
       "L 102.444094 67.294488 \n",
       "L 102.444094 67.294488 \n",
       "L 114.349606 51.420472 \n",
       "L 112.648819 50.144882 \n",
       "L 116.050394 49.152756 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_4\">\n",
       "    <path clip-path=\"url(#pe4a5b6deb6)\" d=\"M 109.247244 148.932283 \n",
       "L 106.412598 151.058268 \n",
       "L 106.412598 148.932283 \n",
       "L 75.231496 148.932283 \n",
       "L 75.231496 148.932283 \n",
       "L 106.412598 148.932283 \n",
       "L 106.412598 146.806299 \n",
       "L 109.247244 148.932283 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_5\">\n",
       "    <path clip-path=\"url(#pe4a5b6deb6)\" d=\"M 75.231496 148.932283 \n",
       "L 78.066142 146.806299 \n",
       "L 78.066142 148.932283 \n",
       "L 109.247244 148.932283 \n",
       "L 109.247244 148.932283 \n",
       "L 78.066142 148.932283 \n",
       "L 78.066142 151.058268 \n",
       "L 75.231496 148.932283 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_6\">\n",
       "    <path clip-path=\"url(#pe4a5b6deb6)\" d=\"M 58.223622 52.554331 \n",
       "C 62.734163 52.554331 67.060571 50.762274 70.250005 47.57284 \n",
       "C 73.439439 44.383406 75.231496 40.056998 75.231496 35.546457 \n",
       "C 75.231496 31.035916 73.439439 26.709508 70.250005 23.520074 \n",
       "C 67.060571 20.33064 62.734163 18.538583 58.223622 18.538583 \n",
       "C 53.713081 18.538583 49.386673 20.33064 46.197239 23.520074 \n",
       "C 43.007805 26.709508 41.215748 31.035916 41.215748 35.546457 \n",
       "C 41.215748 40.056998 43.007805 44.383406 46.197239 47.57284 \n",
       "C 49.386673 50.762274 53.713081 52.554331 58.223622 52.554331 \n",
       "L 58.223622 52.554331 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_7\">\n",
       "    <path clip-path=\"url(#pe4a5b6deb6)\" d=\"M 92.23937 97.908661 \n",
       "C 96.749911 97.908661 101.076319 96.116605 104.265753 92.92717 \n",
       "C 107.455187 89.737736 109.247244 85.411328 109.247244 80.900787 \n",
       "C 109.247244 76.390246 107.455187 72.063838 104.265753 68.874404 \n",
       "C 101.076319 65.68497 96.749911 63.892913 92.23937 63.892913 \n",
       "C 87.728829 63.892913 83.402421 65.68497 80.212987 68.874404 \n",
       "C 77.023553 72.063838 75.231496 76.390246 75.231496 80.900787 \n",
       "C 75.231496 85.411328 77.023553 89.737736 80.212987 92.92717 \n",
       "C 83.402421 96.116605 87.728829 97.908661 92.23937 97.908661 \n",
       "L 92.23937 97.908661 \n",
       "z\n",
       "\" style=\"fill:none;opacity:0.25;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_8\">\n",
       "    <path clip-path=\"url(#pe4a5b6deb6)\" d=\"M 126.255118 52.554331 \n",
       "C 130.765659 52.554331 135.092067 50.762274 138.281501 47.57284 \n",
       "C 141.470935 44.383406 143.262992 40.056998 143.262992 35.546457 \n",
       "C 143.262992 31.035916 141.470935 26.709508 138.281501 23.520074 \n",
       "C 135.092067 20.33064 130.765659 18.538583 126.255118 18.538583 \n",
       "C 121.744577 18.538583 117.418169 20.33064 114.228735 23.520074 \n",
       "C 111.039301 26.709508 109.247244 31.035916 109.247244 35.546457 \n",
       "C 109.247244 40.056998 111.039301 44.383406 114.228735 47.57284 \n",
       "C 117.418169 50.762274 121.744577 52.554331 126.255118 52.554331 \n",
       "L 126.255118 52.554331 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_9\">\n",
       "    <path clip-path=\"url(#pe4a5b6deb6)\" d=\"M 126.255118 165.940157 \n",
       "C 130.765659 165.940157 135.092067 164.148101 138.281501 160.958667 \n",
       "C 141.470935 157.769232 143.262992 153.442824 143.262992 148.932283 \n",
       "C 143.262992 144.421743 141.470935 140.095334 138.281501 136.9059 \n",
       "C 135.092067 133.716466 130.765659 131.924409 126.255118 131.924409 \n",
       "C 121.744577 131.924409 117.418169 133.716466 114.228735 136.9059 \n",
       "C 111.039301 140.095334 109.247244 144.421743 109.247244 148.932283 \n",
       "C 109.247244 153.442824 111.039301 157.769232 114.228735 160.958667 \n",
       "C 117.418169 164.148101 121.744577 165.940157 126.255118 165.940157 \n",
       "L 126.255118 165.940157 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_10\">\n",
       "    <path clip-path=\"url(#pe4a5b6deb6)\" d=\"M 58.223622 165.940157 \n",
       "C 62.734163 165.940157 67.060571 164.148101 70.250005 160.958667 \n",
       "C 73.439439 157.769232 75.231496 153.442824 75.231496 148.932283 \n",
       "C 75.231496 144.421743 73.439439 140.095334 70.250005 136.9059 \n",
       "C 67.060571 133.716466 62.734163 131.924409 58.223622 131.924409 \n",
       "C 53.713081 131.924409 49.386673 133.716466 46.197239 136.9059 \n",
       "C 43.007805 140.095334 41.215748 144.421743 41.215748 148.932283 \n",
       "C 41.215748 153.442824 43.007805 157.769232 46.197239 160.958667 \n",
       "C 49.386673 164.148101 53.713081 165.940157 58.223622 165.940157 \n",
       "L 58.223622 165.940157 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"matplotlib.axis_1\"/>\n",
       "   <g id=\"matplotlib.axis_2\"/>\n",
       "   <g id=\"text_1\">\n",
       "    <!-- A -->\n",
       "    <defs>\n",
       "     <path d=\"M 34.1875 63.1875 \n",
       "L 20.796875 26.90625 \n",
       "L 47.609375 26.90625 \n",
       "z\n",
       "M 28.609375 72.90625 \n",
       "L 39.796875 72.90625 \n",
       "L 67.578125 0 \n",
       "L 57.328125 0 \n",
       "L 50.6875 18.703125 \n",
       "L 17.828125 18.703125 \n",
       "L 11.1875 0 \n",
       "L 0.78125 0 \n",
       "z\n",
       "\" id=\"BitstreamVeraSans-Roman-41\"/>\n",
       "    </defs>\n",
       "    <g transform=\"translate(52.0670595472 40.5133316929)scale(0.18 -0.18)\">\n",
       "     <use xlink:href=\"#BitstreamVeraSans-Roman-41\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"text_2\">\n",
       "    <!-- C -->\n",
       "    <defs>\n",
       "     <path d=\"M 64.40625 67.28125 \n",
       "L 64.40625 56.890625 \n",
       "Q 59.421875 61.53125 53.78125 63.8125 \n",
       "Q 48.140625 66.109375 41.796875 66.109375 \n",
       "Q 29.296875 66.109375 22.65625 58.46875 \n",
       "Q 16.015625 50.828125 16.015625 36.375 \n",
       "Q 16.015625 21.96875 22.65625 14.328125 \n",
       "Q 29.296875 6.6875 41.796875 6.6875 \n",
       "Q 48.140625 6.6875 53.78125 8.984375 \n",
       "Q 59.421875 11.28125 64.40625 15.921875 \n",
       "L 64.40625 5.609375 \n",
       "Q 59.234375 2.09375 53.4375 0.328125 \n",
       "Q 47.65625 -1.421875 41.21875 -1.421875 \n",
       "Q 24.65625 -1.421875 15.125 8.703125 \n",
       "Q 5.609375 18.84375 5.609375 36.375 \n",
       "Q 5.609375 53.953125 15.125 64.078125 \n",
       "Q 24.65625 74.21875 41.21875 74.21875 \n",
       "Q 47.75 74.21875 53.53125 72.484375 \n",
       "Q 59.328125 70.75 64.40625 67.28125 \n",
       "\" id=\"BitstreamVeraSans-Roman-43\"/>\n",
       "    </defs>\n",
       "    <g style=\"opacity:0.25;\" transform=\"translate(85.9548388287 85.8676624016)scale(0.18 -0.18)\">\n",
       "     <use xlink:href=\"#BitstreamVeraSans-Roman-43\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"text_3\">\n",
       "    <!-- B -->\n",
       "    <defs>\n",
       "     <path d=\"M 19.671875 34.8125 \n",
       "L 19.671875 8.109375 \n",
       "L 35.5 8.109375 \n",
       "Q 43.453125 8.109375 47.28125 11.40625 \n",
       "Q 51.125 14.703125 51.125 21.484375 \n",
       "Q 51.125 28.328125 47.28125 31.5625 \n",
       "Q 43.453125 34.8125 35.5 34.8125 \n",
       "z\n",
       "M 19.671875 64.796875 \n",
       "L 19.671875 42.828125 \n",
       "L 34.28125 42.828125 \n",
       "Q 41.5 42.828125 45.03125 45.53125 \n",
       "Q 48.578125 48.25 48.578125 53.8125 \n",
       "Q 48.578125 59.328125 45.03125 62.0625 \n",
       "Q 41.5 64.796875 34.28125 64.796875 \n",
       "z\n",
       "M 9.8125 72.90625 \n",
       "L 35.015625 72.90625 \n",
       "Q 46.296875 72.90625 52.390625 68.21875 \n",
       "Q 58.5 63.53125 58.5 54.890625 \n",
       "Q 58.5 48.1875 55.375 44.234375 \n",
       "Q 52.25 40.28125 46.1875 39.3125 \n",
       "Q 53.46875 37.75 57.5 32.78125 \n",
       "Q 61.53125 27.828125 61.53125 20.40625 \n",
       "Q 61.53125 10.640625 54.890625 5.3125 \n",
       "Q 48.25 0 35.984375 0 \n",
       "L 9.8125 0 \n",
       "z\n",
       "\" id=\"BitstreamVeraSans-Roman-42\"/>\n",
       "    </defs>\n",
       "    <g transform=\"translate(120.08027436 40.5133316929)scale(0.18 -0.18)\">\n",
       "     <use xlink:href=\"#BitstreamVeraSans-Roman-42\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"text_4\">\n",
       "    <!-- B -->\n",
       "    <g transform=\"translate(120.08027436 153.899158465)scale(0.18 -0.18)\">\n",
       "     <use xlink:href=\"#BitstreamVeraSans-Roman-42\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"text_5\">\n",
       "    <!-- A -->\n",
       "    <g transform=\"translate(52.0670595472 153.899158465)scale(0.18 -0.18)\">\n",
       "     <use xlink:href=\"#BitstreamVeraSans-Roman-41\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "  </g>\n",
       " </g>\n",
       " <defs>\n",
       "  <clipPath id=\"pe4a5b6deb6\">\n",
       "   <rect height=\"170.078740157\" width=\"141.732283465\" x=\"7.2\" y=\"7.2\"/>\n",
       "  </clipPath>\n",
       " </defs>\n",
       "</svg>\n"
      ],
      "text/plain": [
       "<matplotlib.figure.Figure at 0x7feb96a134e0>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "pgm = daft.PGM([2.5, 3], origin=[-0.5, 0.5])\n",
    "add_node(pgm, 'A', 'A', 0.4, 3)\n",
    "add_node(pgm, 'C', 'C', 1, 2.2,  plot_params={'alpha': 0.25}, label_params={'alpha': 0.25})\n",
    "add_node(pgm, 'B', 'B', 1.6, 3)\n",
    "add_node(pgm, 'A2', 'A', 0.4, 1)\n",
    "add_node(pgm, 'B2', 'B', 1.6, 1)\n",
    "add_edges(pgm, [\n",
    "        ('C', 'A'),\n",
    "        ('C', 'B'),\n",
    "        ('A2', 'B2'),\n",
    "        ('B2', 'A2')\n",
    "    ])\n",
    "pgm.render()\n",
    "save('bn_prop_05')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "image/svg+xml": [
       "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"no\"?>\n",
       "<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\n",
       "  \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n",
       "<!-- Created with matplotlib (http://matplotlib.org/) -->\n",
       "<svg height=\"184pt\" version=\"1.1\" viewBox=\"0 0 156 184\" width=\"156pt\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n",
       " <defs>\n",
       "  <style type=\"text/css\">\n",
       "*{stroke-linecap:butt;stroke-linejoin:round;stroke-miterlimit:100000;}\n",
       "  </style>\n",
       " </defs>\n",
       " <g id=\"figure_1\">\n",
       "  <g id=\"patch_1\">\n",
       "   <path d=\"M 0 184.47874 \n",
       "L 156.132283 184.47874 \n",
       "L 156.132283 0 \n",
       "L 0 0 \n",
       "L 0 184.47874 \n",
       "z\n",
       "\" style=\"fill:none;\"/>\n",
       "  </g>\n",
       "  <g id=\"axes_1\">\n",
       "   <g id=\"patch_2\">\n",
       "    <path clip-path=\"url(#p96dccff708)\" d=\"M 68.428346 49.152756 \n",
       "L 71.829921 50.144882 \n",
       "L 70.129134 51.420472 \n",
       "L 82.034646 67.294488 \n",
       "L 82.034646 67.294488 \n",
       "L 70.129134 51.420472 \n",
       "L 68.428346 52.696063 \n",
       "L 68.428346 49.152756 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_3\">\n",
       "    <path clip-path=\"url(#p96dccff708)\" d=\"M 116.050394 49.152756 \n",
       "L 116.050394 52.696063 \n",
       "L 114.349606 51.420472 \n",
       "L 102.444094 67.294488 \n",
       "L 102.444094 67.294488 \n",
       "L 114.349606 51.420472 \n",
       "L 112.648819 50.144882 \n",
       "L 116.050394 49.152756 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_4\">\n",
       "    <path clip-path=\"url(#p96dccff708)\" d=\"M 58.223622 52.554331 \n",
       "C 62.734163 52.554331 67.060571 50.762274 70.250005 47.57284 \n",
       "C 73.439439 44.383406 75.231496 40.056998 75.231496 35.546457 \n",
       "C 75.231496 31.035916 73.439439 26.709508 70.250005 23.520074 \n",
       "C 67.060571 20.33064 62.734163 18.538583 58.223622 18.538583 \n",
       "C 53.713081 18.538583 49.386673 20.33064 46.197239 23.520074 \n",
       "C 43.007805 26.709508 41.215748 31.035916 41.215748 35.546457 \n",
       "C 41.215748 40.056998 43.007805 44.383406 46.197239 47.57284 \n",
       "C 49.386673 50.762274 53.713081 52.554331 58.223622 52.554331 \n",
       "L 58.223622 52.554331 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_5\">\n",
       "    <path clip-path=\"url(#p96dccff708)\" d=\"M 92.23937 97.908661 \n",
       "C 96.749911 97.908661 101.076319 96.116605 104.265753 92.92717 \n",
       "C 107.455187 89.737736 109.247244 85.411328 109.247244 80.900787 \n",
       "C 109.247244 76.390246 107.455187 72.063838 104.265753 68.874404 \n",
       "C 101.076319 65.68497 96.749911 63.892913 92.23937 63.892913 \n",
       "C 87.728829 63.892913 83.402421 65.68497 80.212987 68.874404 \n",
       "C 77.023553 72.063838 75.231496 76.390246 75.231496 80.900787 \n",
       "C 75.231496 85.411328 77.023553 89.737736 80.212987 92.92717 \n",
       "C 83.402421 96.116605 87.728829 97.908661 92.23937 97.908661 \n",
       "z\n",
       "\" style=\"fill:#386df9;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_6\">\n",
       "    <path clip-path=\"url(#p96dccff708)\" d=\"M 126.255118 52.554331 \n",
       "C 130.765659 52.554331 135.092067 50.762274 138.281501 47.57284 \n",
       "C 141.470935 44.383406 143.262992 40.056998 143.262992 35.546457 \n",
       "C 143.262992 31.035916 141.470935 26.709508 138.281501 23.520074 \n",
       "C 135.092067 20.33064 130.765659 18.538583 126.255118 18.538583 \n",
       "C 121.744577 18.538583 117.418169 20.33064 114.228735 23.520074 \n",
       "C 111.039301 26.709508 109.247244 31.035916 109.247244 35.546457 \n",
       "C 109.247244 40.056998 111.039301 44.383406 114.228735 47.57284 \n",
       "C 117.418169 50.762274 121.744577 52.554331 126.255118 52.554331 \n",
       "L 126.255118 52.554331 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_7\">\n",
       "    <path clip-path=\"url(#p96dccff708)\" d=\"M 126.255118 165.940157 \n",
       "C 130.765659 165.940157 135.092067 164.148101 138.281501 160.958667 \n",
       "C 141.470935 157.769232 143.262992 153.442824 143.262992 148.932283 \n",
       "C 143.262992 144.421743 141.470935 140.095334 138.281501 136.9059 \n",
       "C 135.092067 133.716466 130.765659 131.924409 126.255118 131.924409 \n",
       "C 121.744577 131.924409 117.418169 133.716466 114.228735 136.9059 \n",
       "C 111.039301 140.095334 109.247244 144.421743 109.247244 148.932283 \n",
       "C 109.247244 153.442824 111.039301 157.769232 114.228735 160.958667 \n",
       "C 117.418169 164.148101 121.744577 165.940157 126.255118 165.940157 \n",
       "L 126.255118 165.940157 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_8\">\n",
       "    <path clip-path=\"url(#p96dccff708)\" d=\"M 58.223622 165.940157 \n",
       "C 62.734163 165.940157 67.060571 164.148101 70.250005 160.958667 \n",
       "C 73.439439 157.769232 75.231496 153.442824 75.231496 148.932283 \n",
       "C 75.231496 144.421743 73.439439 140.095334 70.250005 136.9059 \n",
       "C 67.060571 133.716466 62.734163 131.924409 58.223622 131.924409 \n",
       "C 53.713081 131.924409 49.386673 133.716466 46.197239 136.9059 \n",
       "C 43.007805 140.095334 41.215748 144.421743 41.215748 148.932283 \n",
       "C 41.215748 153.442824 43.007805 157.769232 46.197239 160.958667 \n",
       "C 49.386673 164.148101 53.713081 165.940157 58.223622 165.940157 \n",
       "L 58.223622 165.940157 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"matplotlib.axis_1\"/>\n",
       "   <g id=\"matplotlib.axis_2\"/>\n",
       "   <g id=\"text_1\">\n",
       "    <!-- A -->\n",
       "    <defs>\n",
       "     <path d=\"M 34.1875 63.1875 \n",
       "L 20.796875 26.90625 \n",
       "L 47.609375 26.90625 \n",
       "z\n",
       "M 28.609375 72.90625 \n",
       "L 39.796875 72.90625 \n",
       "L 67.578125 0 \n",
       "L 57.328125 0 \n",
       "L 50.6875 18.703125 \n",
       "L 17.828125 18.703125 \n",
       "L 11.1875 0 \n",
       "L 0.78125 0 \n",
       "z\n",
       "\" id=\"BitstreamVeraSans-Roman-41\"/>\n",
       "    </defs>\n",
       "    <g transform=\"translate(52.0670595472 40.5133316929)scale(0.18 -0.18)\">\n",
       "     <use xlink:href=\"#BitstreamVeraSans-Roman-41\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"text_2\">\n",
       "    <!-- C -->\n",
       "    <defs>\n",
       "     <path d=\"M 64.40625 67.28125 \n",
       "L 64.40625 56.890625 \n",
       "Q 59.421875 61.53125 53.78125 63.8125 \n",
       "Q 48.140625 66.109375 41.796875 66.109375 \n",
       "Q 29.296875 66.109375 22.65625 58.46875 \n",
       "Q 16.015625 50.828125 16.015625 36.375 \n",
       "Q 16.015625 21.96875 22.65625 14.328125 \n",
       "Q 29.296875 6.6875 41.796875 6.6875 \n",
       "Q 48.140625 6.6875 53.78125 8.984375 \n",
       "Q 59.421875 11.28125 64.40625 15.921875 \n",
       "L 64.40625 5.609375 \n",
       "Q 59.234375 2.09375 53.4375 0.328125 \n",
       "Q 47.65625 -1.421875 41.21875 -1.421875 \n",
       "Q 24.65625 -1.421875 15.125 8.703125 \n",
       "Q 5.609375 18.84375 5.609375 36.375 \n",
       "Q 5.609375 53.953125 15.125 64.078125 \n",
       "Q 24.65625 74.21875 41.21875 74.21875 \n",
       "Q 47.75 74.21875 53.53125 72.484375 \n",
       "Q 59.328125 70.75 64.40625 67.28125 \n",
       "\" id=\"BitstreamVeraSans-Roman-43\"/>\n",
       "    </defs>\n",
       "    <g style=\"fill:#ffffff;\" transform=\"translate(85.9548388287 85.8676624016)scale(0.18 -0.18)\">\n",
       "     <use xlink:href=\"#BitstreamVeraSans-Roman-43\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"text_3\">\n",
       "    <!-- B -->\n",
       "    <defs>\n",
       "     <path d=\"M 19.671875 34.8125 \n",
       "L 19.671875 8.109375 \n",
       "L 35.5 8.109375 \n",
       "Q 43.453125 8.109375 47.28125 11.40625 \n",
       "Q 51.125 14.703125 51.125 21.484375 \n",
       "Q 51.125 28.328125 47.28125 31.5625 \n",
       "Q 43.453125 34.8125 35.5 34.8125 \n",
       "z\n",
       "M 19.671875 64.796875 \n",
       "L 19.671875 42.828125 \n",
       "L 34.28125 42.828125 \n",
       "Q 41.5 42.828125 45.03125 45.53125 \n",
       "Q 48.578125 48.25 48.578125 53.8125 \n",
       "Q 48.578125 59.328125 45.03125 62.0625 \n",
       "Q 41.5 64.796875 34.28125 64.796875 \n",
       "z\n",
       "M 9.8125 72.90625 \n",
       "L 35.015625 72.90625 \n",
       "Q 46.296875 72.90625 52.390625 68.21875 \n",
       "Q 58.5 63.53125 58.5 54.890625 \n",
       "Q 58.5 48.1875 55.375 44.234375 \n",
       "Q 52.25 40.28125 46.1875 39.3125 \n",
       "Q 53.46875 37.75 57.5 32.78125 \n",
       "Q 61.53125 27.828125 61.53125 20.40625 \n",
       "Q 61.53125 10.640625 54.890625 5.3125 \n",
       "Q 48.25 0 35.984375 0 \n",
       "L 9.8125 0 \n",
       "z\n",
       "\" id=\"BitstreamVeraSans-Roman-42\"/>\n",
       "    </defs>\n",
       "    <g transform=\"translate(120.08027436 40.5133316929)scale(0.18 -0.18)\">\n",
       "     <use xlink:href=\"#BitstreamVeraSans-Roman-42\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"text_4\">\n",
       "    <!-- B -->\n",
       "    <g transform=\"translate(120.08027436 153.899158465)scale(0.18 -0.18)\">\n",
       "     <use xlink:href=\"#BitstreamVeraSans-Roman-42\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"text_5\">\n",
       "    <!-- A -->\n",
       "    <g transform=\"translate(52.0670595472 153.899158465)scale(0.18 -0.18)\">\n",
       "     <use xlink:href=\"#BitstreamVeraSans-Roman-41\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "  </g>\n",
       " </g>\n",
       " <defs>\n",
       "  <clipPath id=\"p96dccff708\">\n",
       "   <rect height=\"170.078740157\" width=\"141.732283465\" x=\"7.2\" y=\"7.2\"/>\n",
       "  </clipPath>\n",
       " </defs>\n",
       "</svg>\n"
      ],
      "text/plain": [
       "<matplotlib.figure.Figure at 0x7feb969756d8>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "pgm = daft.PGM([2.5, 3], origin=[-0.5, 0.5])\n",
    "add_node(pgm, 'A', 'A', 0.4, 3)\n",
    "add_node(pgm, 'C', 'C', 1, 2.2,  plot_params={'facecolor': '#386DF9'}, label_params={'color': 'w'})\n",
    "add_node(pgm, 'B', 'B', 1.6, 3)\n",
    "add_node(pgm, 'A2', 'A', 0.4, 1)\n",
    "add_node(pgm, 'B2', 'B', 1.6, 1)\n",
    "add_edges(pgm, [\n",
    "        ('C', 'A'),\n",
    "        ('C', 'B'),\n",
    "    ])\n",
    "pgm.render()\n",
    "save('bn_prop_06')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "image/svg+xml": [
       "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"no\"?>\n",
       "<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\n",
       "  \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n",
       "<!-- Created with matplotlib (http://matplotlib.org/) -->\n",
       "<svg height=\"184pt\" version=\"1.1\" viewBox=\"0 0 156 184\" width=\"156pt\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n",
       " <defs>\n",
       "  <style type=\"text/css\">\n",
       "*{stroke-linecap:butt;stroke-linejoin:round;stroke-miterlimit:100000;}\n",
       "  </style>\n",
       " </defs>\n",
       " <g id=\"figure_1\">\n",
       "  <g id=\"patch_1\">\n",
       "   <path d=\"M 0 184.47874 \n",
       "L 156.132283 184.47874 \n",
       "L 156.132283 0 \n",
       "L 0 0 \n",
       "L 0 184.47874 \n",
       "z\n",
       "\" style=\"fill:none;\"/>\n",
       "  </g>\n",
       "  <g id=\"axes_1\">\n",
       "   <g id=\"patch_2\">\n",
       "    <path clip-path=\"url(#p5719c98f06)\" d=\"M 82.034646 67.294488 \n",
       "L 78.633071 66.302362 \n",
       "L 80.333858 65.026772 \n",
       "L 68.428346 49.152756 \n",
       "L 68.428346 49.152756 \n",
       "L 80.333858 65.026772 \n",
       "L 82.034646 63.751181 \n",
       "L 82.034646 67.294488 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_3\">\n",
       "    <path clip-path=\"url(#p5719c98f06)\" d=\"M 116.050394 49.152756 \n",
       "L 116.050394 52.696063 \n",
       "L 114.349606 51.420472 \n",
       "L 102.444094 67.294488 \n",
       "L 102.444094 67.294488 \n",
       "L 114.349606 51.420472 \n",
       "L 112.648819 50.144882 \n",
       "L 116.050394 49.152756 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_4\">\n",
       "    <path clip-path=\"url(#p5719c98f06)\" d=\"M 58.223622 52.554331 \n",
       "C 62.734163 52.554331 67.060571 50.762274 70.250005 47.57284 \n",
       "C 73.439439 44.383406 75.231496 40.056998 75.231496 35.546457 \n",
       "C 75.231496 31.035916 73.439439 26.709508 70.250005 23.520074 \n",
       "C 67.060571 20.33064 62.734163 18.538583 58.223622 18.538583 \n",
       "C 53.713081 18.538583 49.386673 20.33064 46.197239 23.520074 \n",
       "C 43.007805 26.709508 41.215748 31.035916 41.215748 35.546457 \n",
       "C 41.215748 40.056998 43.007805 44.383406 46.197239 47.57284 \n",
       "C 49.386673 50.762274 53.713081 52.554331 58.223622 52.554331 \n",
       "L 58.223622 52.554331 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_5\">\n",
       "    <path clip-path=\"url(#p5719c98f06)\" d=\"M 92.23937 97.908661 \n",
       "C 96.749911 97.908661 101.076319 96.116605 104.265753 92.92717 \n",
       "C 107.455187 89.737736 109.247244 85.411328 109.247244 80.900787 \n",
       "C 109.247244 76.390246 107.455187 72.063838 104.265753 68.874404 \n",
       "C 101.076319 65.68497 96.749911 63.892913 92.23937 63.892913 \n",
       "C 87.728829 63.892913 83.402421 65.68497 80.212987 68.874404 \n",
       "C 77.023553 72.063838 75.231496 76.390246 75.231496 80.900787 \n",
       "C 75.231496 85.411328 77.023553 89.737736 80.212987 92.92717 \n",
       "C 83.402421 96.116605 87.728829 97.908661 92.23937 97.908661 \n",
       "z\n",
       "\" style=\"fill:#386df9;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_6\">\n",
       "    <path clip-path=\"url(#p5719c98f06)\" d=\"M 126.255118 52.554331 \n",
       "C 130.765659 52.554331 135.092067 50.762274 138.281501 47.57284 \n",
       "C 141.470935 44.383406 143.262992 40.056998 143.262992 35.546457 \n",
       "C 143.262992 31.035916 141.470935 26.709508 138.281501 23.520074 \n",
       "C 135.092067 20.33064 130.765659 18.538583 126.255118 18.538583 \n",
       "C 121.744577 18.538583 117.418169 20.33064 114.228735 23.520074 \n",
       "C 111.039301 26.709508 109.247244 31.035916 109.247244 35.546457 \n",
       "C 109.247244 40.056998 111.039301 44.383406 114.228735 47.57284 \n",
       "C 117.418169 50.762274 121.744577 52.554331 126.255118 52.554331 \n",
       "L 126.255118 52.554331 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_7\">\n",
       "    <path clip-path=\"url(#p5719c98f06)\" d=\"M 126.255118 165.940157 \n",
       "C 130.765659 165.940157 135.092067 164.148101 138.281501 160.958667 \n",
       "C 141.470935 157.769232 143.262992 153.442824 143.262992 148.932283 \n",
       "C 143.262992 144.421743 141.470935 140.095334 138.281501 136.9059 \n",
       "C 135.092067 133.716466 130.765659 131.924409 126.255118 131.924409 \n",
       "C 121.744577 131.924409 117.418169 133.716466 114.228735 136.9059 \n",
       "C 111.039301 140.095334 109.247244 144.421743 109.247244 148.932283 \n",
       "C 109.247244 153.442824 111.039301 157.769232 114.228735 160.958667 \n",
       "C 117.418169 164.148101 121.744577 165.940157 126.255118 165.940157 \n",
       "L 126.255118 165.940157 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_8\">\n",
       "    <path clip-path=\"url(#p5719c98f06)\" d=\"M 58.223622 165.940157 \n",
       "C 62.734163 165.940157 67.060571 164.148101 70.250005 160.958667 \n",
       "C 73.439439 157.769232 75.231496 153.442824 75.231496 148.932283 \n",
       "C 75.231496 144.421743 73.439439 140.095334 70.250005 136.9059 \n",
       "C 67.060571 133.716466 62.734163 131.924409 58.223622 131.924409 \n",
       "C 53.713081 131.924409 49.386673 133.716466 46.197239 136.9059 \n",
       "C 43.007805 140.095334 41.215748 144.421743 41.215748 148.932283 \n",
       "C 41.215748 153.442824 43.007805 157.769232 46.197239 160.958667 \n",
       "C 49.386673 164.148101 53.713081 165.940157 58.223622 165.940157 \n",
       "L 58.223622 165.940157 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"matplotlib.axis_1\"/>\n",
       "   <g id=\"matplotlib.axis_2\"/>\n",
       "   <g id=\"text_1\">\n",
       "    <!-- A -->\n",
       "    <defs>\n",
       "     <path d=\"M 34.1875 63.1875 \n",
       "L 20.796875 26.90625 \n",
       "L 47.609375 26.90625 \n",
       "z\n",
       "M 28.609375 72.90625 \n",
       "L 39.796875 72.90625 \n",
       "L 67.578125 0 \n",
       "L 57.328125 0 \n",
       "L 50.6875 18.703125 \n",
       "L 17.828125 18.703125 \n",
       "L 11.1875 0 \n",
       "L 0.78125 0 \n",
       "z\n",
       "\" id=\"BitstreamVeraSans-Roman-41\"/>\n",
       "    </defs>\n",
       "    <g transform=\"translate(52.0670595472 40.5133316929)scale(0.18 -0.18)\">\n",
       "     <use xlink:href=\"#BitstreamVeraSans-Roman-41\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"text_2\">\n",
       "    <!-- C -->\n",
       "    <defs>\n",
       "     <path d=\"M 64.40625 67.28125 \n",
       "L 64.40625 56.890625 \n",
       "Q 59.421875 61.53125 53.78125 63.8125 \n",
       "Q 48.140625 66.109375 41.796875 66.109375 \n",
       "Q 29.296875 66.109375 22.65625 58.46875 \n",
       "Q 16.015625 50.828125 16.015625 36.375 \n",
       "Q 16.015625 21.96875 22.65625 14.328125 \n",
       "Q 29.296875 6.6875 41.796875 6.6875 \n",
       "Q 48.140625 6.6875 53.78125 8.984375 \n",
       "Q 59.421875 11.28125 64.40625 15.921875 \n",
       "L 64.40625 5.609375 \n",
       "Q 59.234375 2.09375 53.4375 0.328125 \n",
       "Q 47.65625 -1.421875 41.21875 -1.421875 \n",
       "Q 24.65625 -1.421875 15.125 8.703125 \n",
       "Q 5.609375 18.84375 5.609375 36.375 \n",
       "Q 5.609375 53.953125 15.125 64.078125 \n",
       "Q 24.65625 74.21875 41.21875 74.21875 \n",
       "Q 47.75 74.21875 53.53125 72.484375 \n",
       "Q 59.328125 70.75 64.40625 67.28125 \n",
       "\" id=\"BitstreamVeraSans-Roman-43\"/>\n",
       "    </defs>\n",
       "    <g style=\"fill:#ffffff;\" transform=\"translate(85.9548388287 85.8676624016)scale(0.18 -0.18)\">\n",
       "     <use xlink:href=\"#BitstreamVeraSans-Roman-43\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"text_3\">\n",
       "    <!-- B -->\n",
       "    <defs>\n",
       "     <path d=\"M 19.671875 34.8125 \n",
       "L 19.671875 8.109375 \n",
       "L 35.5 8.109375 \n",
       "Q 43.453125 8.109375 47.28125 11.40625 \n",
       "Q 51.125 14.703125 51.125 21.484375 \n",
       "Q 51.125 28.328125 47.28125 31.5625 \n",
       "Q 43.453125 34.8125 35.5 34.8125 \n",
       "z\n",
       "M 19.671875 64.796875 \n",
       "L 19.671875 42.828125 \n",
       "L 34.28125 42.828125 \n",
       "Q 41.5 42.828125 45.03125 45.53125 \n",
       "Q 48.578125 48.25 48.578125 53.8125 \n",
       "Q 48.578125 59.328125 45.03125 62.0625 \n",
       "Q 41.5 64.796875 34.28125 64.796875 \n",
       "z\n",
       "M 9.8125 72.90625 \n",
       "L 35.015625 72.90625 \n",
       "Q 46.296875 72.90625 52.390625 68.21875 \n",
       "Q 58.5 63.53125 58.5 54.890625 \n",
       "Q 58.5 48.1875 55.375 44.234375 \n",
       "Q 52.25 40.28125 46.1875 39.3125 \n",
       "Q 53.46875 37.75 57.5 32.78125 \n",
       "Q 61.53125 27.828125 61.53125 20.40625 \n",
       "Q 61.53125 10.640625 54.890625 5.3125 \n",
       "Q 48.25 0 35.984375 0 \n",
       "L 9.8125 0 \n",
       "z\n",
       "\" id=\"BitstreamVeraSans-Roman-42\"/>\n",
       "    </defs>\n",
       "    <g transform=\"translate(120.08027436 40.5133316929)scale(0.18 -0.18)\">\n",
       "     <use xlink:href=\"#BitstreamVeraSans-Roman-42\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"text_4\">\n",
       "    <!-- B -->\n",
       "    <g transform=\"translate(120.08027436 153.899158465)scale(0.18 -0.18)\">\n",
       "     <use xlink:href=\"#BitstreamVeraSans-Roman-42\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"text_5\">\n",
       "    <!-- A -->\n",
       "    <g transform=\"translate(52.0670595472 153.899158465)scale(0.18 -0.18)\">\n",
       "     <use xlink:href=\"#BitstreamVeraSans-Roman-41\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "  </g>\n",
       " </g>\n",
       " <defs>\n",
       "  <clipPath id=\"p5719c98f06\">\n",
       "   <rect height=\"170.078740157\" width=\"141.732283465\" x=\"7.2\" y=\"7.2\"/>\n",
       "  </clipPath>\n",
       " </defs>\n",
       "</svg>\n"
      ],
      "text/plain": [
       "<matplotlib.figure.Figure at 0x7feb969754e0>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "pgm = daft.PGM([2.5, 3], origin=[-0.5, 0.5])\n",
    "add_node(pgm, 'A', 'A', 0.4, 3)\n",
    "add_node(pgm, 'C', 'C', 1, 2.2,  plot_params={'facecolor': '#386DF9'}, label_params={'color': 'w'})\n",
    "add_node(pgm, 'B', 'B', 1.6, 3)\n",
    "add_node(pgm, 'A2', 'A', 0.4, 1)\n",
    "add_node(pgm, 'B2', 'B', 1.6, 1)\n",
    "add_edges(pgm, [\n",
    "        ('A', 'C'),\n",
    "        ('C', 'B'),\n",
    "    ])\n",
    "pgm.render()\n",
    "save('bn_prop_07')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {
    "collapsed": false,
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "image/svg+xml": [
       "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"no\"?>\n",
       "<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\n",
       "  \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n",
       "<!-- Created with matplotlib (http://matplotlib.org/) -->\n",
       "<svg height=\"127pt\" version=\"1.1\" viewBox=\"0 0 439 127\" width=\"439pt\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n",
       " <defs>\n",
       "  <style type=\"text/css\">\n",
       "*{stroke-linecap:butt;stroke-linejoin:round;stroke-miterlimit:100000;}\n",
       "  </style>\n",
       " </defs>\n",
       " <g id=\"figure_1\">\n",
       "  <g id=\"patch_1\">\n",
       "   <path d=\"M -0 127.785827 \n",
       "L 439.59685 127.785827 \n",
       "L 439.59685 0 \n",
       "L -0 0 \n",
       "L -0 127.785827 \n",
       "z\n",
       "\" style=\"fill:none;\"/>\n",
       "  </g>\n",
       "  <g id=\"axes_1\">\n",
       "   <g id=\"patch_2\">\n",
       "    <path clip-path=\"url(#pe907e6a6b8)\" d=\"M 68.428346 49.152756 \n",
       "L 71.829921 50.144882 \n",
       "L 70.129134 51.420472 \n",
       "L 82.034646 67.294488 \n",
       "L 82.034646 67.294488 \n",
       "L 70.129134 51.420472 \n",
       "L 68.428346 52.696063 \n",
       "L 68.428346 49.152756 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_3\">\n",
       "    <path clip-path=\"url(#pe907e6a6b8)\" d=\"M 116.050394 49.152756 \n",
       "L 116.050394 52.696063 \n",
       "L 114.349606 51.420472 \n",
       "L 102.444094 67.294488 \n",
       "L 102.444094 67.294488 \n",
       "L 114.349606 51.420472 \n",
       "L 112.648819 50.144882 \n",
       "L 116.050394 49.152756 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_4\">\n",
       "    <path clip-path=\"url(#pe907e6a6b8)\" d=\"M 210.16063 49.152756 \n",
       "L 213.562205 50.144882 \n",
       "L 211.861417 51.420472 \n",
       "L 223.766929 67.294488 \n",
       "L 223.766929 67.294488 \n",
       "L 211.861417 51.420472 \n",
       "L 210.16063 52.696063 \n",
       "L 210.16063 49.152756 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_5\">\n",
       "    <path clip-path=\"url(#pe907e6a6b8)\" d=\"M 244.176378 67.294488 \n",
       "L 244.176378 63.751181 \n",
       "L 245.877165 65.026772 \n",
       "L 257.782677 49.152756 \n",
       "L 257.782677 49.152756 \n",
       "L 245.877165 65.026772 \n",
       "L 247.577953 66.302362 \n",
       "L 244.176378 67.294488 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_6\">\n",
       "    <path clip-path=\"url(#pe907e6a6b8)\" d=\"M 365.499213 67.294488 \n",
       "L 362.097638 66.302362 \n",
       "L 363.798425 65.026772 \n",
       "L 351.892913 49.152756 \n",
       "L 351.892913 49.152756 \n",
       "L 363.798425 65.026772 \n",
       "L 365.499213 63.751181 \n",
       "L 365.499213 67.294488 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_7\">\n",
       "    <path clip-path=\"url(#pe907e6a6b8)\" d=\"M 399.514961 49.152756 \n",
       "L 399.514961 52.696063 \n",
       "L 397.814173 51.420472 \n",
       "L 385.908661 67.294488 \n",
       "L 385.908661 67.294488 \n",
       "L 397.814173 51.420472 \n",
       "L 396.113386 50.144882 \n",
       "L 399.514961 49.152756 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_8\">\n",
       "    <path clip-path=\"url(#pe907e6a6b8)\" d=\"M 92.23937 97.908661 \n",
       "C 96.749911 97.908661 101.076319 96.116605 104.265753 92.92717 \n",
       "C 107.455187 89.737736 109.247244 85.411328 109.247244 80.900787 \n",
       "C 109.247244 76.390246 107.455187 72.063838 104.265753 68.874404 \n",
       "C 101.076319 65.68497 96.749911 63.892913 92.23937 63.892913 \n",
       "C 87.728829 63.892913 83.402421 65.68497 80.212987 68.874404 \n",
       "C 77.023553 72.063838 75.231496 76.390246 75.231496 80.900787 \n",
       "C 75.231496 85.411328 77.023553 89.737736 80.212987 92.92717 \n",
       "C 83.402421 96.116605 87.728829 97.908661 92.23937 97.908661 \n",
       "L 92.23937 97.908661 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_9\">\n",
       "    <path clip-path=\"url(#pe907e6a6b8)\" d=\"M 267.987402 52.554331 \n",
       "C 272.497942 52.554331 276.824351 50.762274 280.013785 47.57284 \n",
       "C 283.203219 44.383406 284.995276 40.056998 284.995276 35.546457 \n",
       "C 284.995276 31.035916 283.203219 26.709508 280.013785 23.520074 \n",
       "C 276.824351 20.33064 272.497942 18.538583 267.987402 18.538583 \n",
       "C 263.476861 18.538583 259.150453 20.33064 255.961019 23.520074 \n",
       "C 252.771584 26.709508 250.979528 31.035916 250.979528 35.546457 \n",
       "C 250.979528 40.056998 252.771584 44.383406 255.961019 47.57284 \n",
       "C 259.150453 50.762274 263.476861 52.554331 267.987402 52.554331 \n",
       "L 267.987402 52.554331 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_10\">\n",
       "    <path clip-path=\"url(#pe907e6a6b8)\" d=\"M 126.255118 52.554331 \n",
       "C 130.765659 52.554331 135.092067 50.762274 138.281501 47.57284 \n",
       "C 141.470935 44.383406 143.262992 40.056998 143.262992 35.546457 \n",
       "C 143.262992 31.035916 141.470935 26.709508 138.281501 23.520074 \n",
       "C 135.092067 20.33064 130.765659 18.538583 126.255118 18.538583 \n",
       "C 121.744577 18.538583 117.418169 20.33064 114.228735 23.520074 \n",
       "C 111.039301 26.709508 109.247244 31.035916 109.247244 35.546457 \n",
       "C 109.247244 40.056998 111.039301 44.383406 114.228735 47.57284 \n",
       "C 117.418169 50.762274 121.744577 52.554331 126.255118 52.554331 \n",
       "L 126.255118 52.554331 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_11\">\n",
       "    <path clip-path=\"url(#pe907e6a6b8)\" d=\"M 341.688189 52.554331 \n",
       "C 346.19873 52.554331 350.525138 50.762274 353.714572 47.57284 \n",
       "C 356.904006 44.383406 358.696063 40.056998 358.696063 35.546457 \n",
       "C 358.696063 31.035916 356.904006 26.709508 353.714572 23.520074 \n",
       "C 350.525138 20.33064 346.19873 18.538583 341.688189 18.538583 \n",
       "C 337.177648 18.538583 332.85124 20.33064 329.661806 23.520074 \n",
       "C 326.472372 26.709508 324.680315 31.035916 324.680315 35.546457 \n",
       "C 324.680315 40.056998 326.472372 44.383406 329.661806 47.57284 \n",
       "C 332.85124 50.762274 337.177648 52.554331 341.688189 52.554331 \n",
       "L 341.688189 52.554331 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_12\">\n",
       "    <path clip-path=\"url(#pe907e6a6b8)\" d=\"M 375.703937 97.908661 \n",
       "C 380.214478 97.908661 384.540886 96.116605 387.73032 92.92717 \n",
       "C 390.919754 89.737736 392.711811 85.411328 392.711811 80.900787 \n",
       "C 392.711811 76.390246 390.919754 72.063838 387.73032 68.874404 \n",
       "C 384.540886 65.68497 380.214478 63.892913 375.703937 63.892913 \n",
       "C 371.193396 63.892913 366.866988 65.68497 363.677554 68.874404 \n",
       "C 360.48812 72.063838 358.696063 76.390246 358.696063 80.900787 \n",
       "C 358.696063 85.411328 360.48812 89.737736 363.677554 92.92717 \n",
       "C 366.866988 96.116605 371.193396 97.908661 375.703937 97.908661 \n",
       "L 375.703937 97.908661 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_13\">\n",
       "    <path clip-path=\"url(#pe907e6a6b8)\" d=\"M 199.955906 52.554331 \n",
       "C 204.466446 52.554331 208.792854 50.762274 211.982289 47.57284 \n",
       "C 215.171723 44.383406 216.96378 40.056998 216.96378 35.546457 \n",
       "C 216.96378 31.035916 215.171723 26.709508 211.982289 23.520074 \n",
       "C 208.792854 20.33064 204.466446 18.538583 199.955906 18.538583 \n",
       "C 195.445365 18.538583 191.118957 20.33064 187.929522 23.520074 \n",
       "C 184.740088 26.709508 182.948031 31.035916 182.948031 35.546457 \n",
       "C 182.948031 40.056998 184.740088 44.383406 187.929522 47.57284 \n",
       "C 191.118957 50.762274 195.445365 52.554331 199.955906 52.554331 \n",
       "L 199.955906 52.554331 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_14\">\n",
       "    <path clip-path=\"url(#pe907e6a6b8)\" d=\"M 409.719685 52.554331 \n",
       "C 414.230226 52.554331 418.556634 50.762274 421.746068 47.57284 \n",
       "C 424.935502 44.383406 426.727559 40.056998 426.727559 35.546457 \n",
       "C 426.727559 31.035916 424.935502 26.709508 421.746068 23.520074 \n",
       "C 418.556634 20.33064 414.230226 18.538583 409.719685 18.538583 \n",
       "C 405.209144 18.538583 400.882736 20.33064 397.693302 23.520074 \n",
       "C 394.503868 26.709508 392.711811 31.035916 392.711811 35.546457 \n",
       "C 392.711811 40.056998 394.503868 44.383406 397.693302 47.57284 \n",
       "C 400.882736 50.762274 405.209144 52.554331 409.719685 52.554331 \n",
       "L 409.719685 52.554331 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_15\">\n",
       "    <path clip-path=\"url(#pe907e6a6b8)\" d=\"M 58.223622 52.554331 \n",
       "C 62.734163 52.554331 67.060571 50.762274 70.250005 47.57284 \n",
       "C 73.439439 44.383406 75.231496 40.056998 75.231496 35.546457 \n",
       "C 75.231496 31.035916 73.439439 26.709508 70.250005 23.520074 \n",
       "C 67.060571 20.33064 62.734163 18.538583 58.223622 18.538583 \n",
       "C 53.713081 18.538583 49.386673 20.33064 46.197239 23.520074 \n",
       "C 43.007805 26.709508 41.215748 31.035916 41.215748 35.546457 \n",
       "C 41.215748 40.056998 43.007805 44.383406 46.197239 47.57284 \n",
       "C 49.386673 50.762274 53.713081 52.554331 58.223622 52.554331 \n",
       "L 58.223622 52.554331 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_16\">\n",
       "    <path clip-path=\"url(#pe907e6a6b8)\" d=\"M 233.971654 97.908661 \n",
       "C 238.482194 97.908661 242.808603 96.116605 245.998037 92.92717 \n",
       "C 249.187471 89.737736 250.979528 85.411328 250.979528 80.900787 \n",
       "C 250.979528 76.390246 249.187471 72.063838 245.998037 68.874404 \n",
       "C 242.808603 65.68497 238.482194 63.892913 233.971654 63.892913 \n",
       "C 229.461113 63.892913 225.134705 65.68497 221.94527 68.874404 \n",
       "C 218.755836 72.063838 216.96378 76.390246 216.96378 80.900787 \n",
       "C 216.96378 85.411328 218.755836 89.737736 221.94527 92.92717 \n",
       "C 225.134705 96.116605 229.461113 97.908661 233.971654 97.908661 \n",
       "L 233.971654 97.908661 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"matplotlib.axis_1\"/>\n",
       "   <g id=\"matplotlib.axis_2\"/>\n",
       "   <g id=\"text_1\">\n",
       "    <!-- C -->\n",
       "    <defs>\n",
       "     <path d=\"M 64.40625 67.28125 \n",
       "L 64.40625 56.890625 \n",
       "Q 59.421875 61.53125 53.78125 63.8125 \n",
       "Q 48.140625 66.109375 41.796875 66.109375 \n",
       "Q 29.296875 66.109375 22.65625 58.46875 \n",
       "Q 16.015625 50.828125 16.015625 36.375 \n",
       "Q 16.015625 21.96875 22.65625 14.328125 \n",
       "Q 29.296875 6.6875 41.796875 6.6875 \n",
       "Q 48.140625 6.6875 53.78125 8.984375 \n",
       "Q 59.421875 11.28125 64.40625 15.921875 \n",
       "L 64.40625 5.609375 \n",
       "Q 59.234375 2.09375 53.4375 0.328125 \n",
       "Q 47.65625 -1.421875 41.21875 -1.421875 \n",
       "Q 24.65625 -1.421875 15.125 8.703125 \n",
       "Q 5.609375 18.84375 5.609375 36.375 \n",
       "Q 5.609375 53.953125 15.125 64.078125 \n",
       "Q 24.65625 74.21875 41.21875 74.21875 \n",
       "Q 47.75 74.21875 53.53125 72.484375 \n",
       "Q 59.328125 70.75 64.40625 67.28125 \n",
       "\" id=\"BitstreamVeraSans-Roman-43\"/>\n",
       "    </defs>\n",
       "    <g transform=\"translate(85.9548388287 85.8676624016)scale(0.18 -0.18)\">\n",
       "     <use xlink:href=\"#BitstreamVeraSans-Roman-43\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"text_2\">\n",
       "    <!-- B -->\n",
       "    <defs>\n",
       "     <path d=\"M 19.671875 34.8125 \n",
       "L 19.671875 8.109375 \n",
       "L 35.5 8.109375 \n",
       "Q 43.453125 8.109375 47.28125 11.40625 \n",
       "Q 51.125 14.703125 51.125 21.484375 \n",
       "Q 51.125 28.328125 47.28125 31.5625 \n",
       "Q 43.453125 34.8125 35.5 34.8125 \n",
       "z\n",
       "M 19.671875 64.796875 \n",
       "L 19.671875 42.828125 \n",
       "L 34.28125 42.828125 \n",
       "Q 41.5 42.828125 45.03125 45.53125 \n",
       "Q 48.578125 48.25 48.578125 53.8125 \n",
       "Q 48.578125 59.328125 45.03125 62.0625 \n",
       "Q 41.5 64.796875 34.28125 64.796875 \n",
       "z\n",
       "M 9.8125 72.90625 \n",
       "L 35.015625 72.90625 \n",
       "Q 46.296875 72.90625 52.390625 68.21875 \n",
       "Q 58.5 63.53125 58.5 54.890625 \n",
       "Q 58.5 48.1875 55.375 44.234375 \n",
       "Q 52.25 40.28125 46.1875 39.3125 \n",
       "Q 53.46875 37.75 57.5 32.78125 \n",
       "Q 61.53125 27.828125 61.53125 20.40625 \n",
       "Q 61.53125 10.640625 54.890625 5.3125 \n",
       "Q 48.25 0 35.984375 0 \n",
       "L 9.8125 0 \n",
       "z\n",
       "\" id=\"BitstreamVeraSans-Roman-42\"/>\n",
       "    </defs>\n",
       "    <g transform=\"translate(261.812557825 40.5133316929)scale(0.18 -0.18)\">\n",
       "     <use xlink:href=\"#BitstreamVeraSans-Roman-42\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"text_3\">\n",
       "    <!-- B -->\n",
       "    <g transform=\"translate(120.08027436 40.5133316929)scale(0.18 -0.18)\">\n",
       "     <use xlink:href=\"#BitstreamVeraSans-Roman-42\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"text_4\">\n",
       "    <!-- A -->\n",
       "    <defs>\n",
       "     <path d=\"M 34.1875 63.1875 \n",
       "L 20.796875 26.90625 \n",
       "L 47.609375 26.90625 \n",
       "z\n",
       "M 28.609375 72.90625 \n",
       "L 39.796875 72.90625 \n",
       "L 67.578125 0 \n",
       "L 57.328125 0 \n",
       "L 50.6875 18.703125 \n",
       "L 17.828125 18.703125 \n",
       "L 11.1875 0 \n",
       "L 0.78125 0 \n",
       "z\n",
       "\" id=\"BitstreamVeraSans-Roman-41\"/>\n",
       "    </defs>\n",
       "    <g transform=\"translate(335.531626476 40.5133316929)scale(0.18 -0.18)\">\n",
       "     <use xlink:href=\"#BitstreamVeraSans-Roman-41\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"text_5\">\n",
       "    <!-- C -->\n",
       "    <g transform=\"translate(369.419405758 85.8676624016)scale(0.18 -0.18)\">\n",
       "     <use xlink:href=\"#BitstreamVeraSans-Roman-43\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"text_6\">\n",
       "    <!-- A -->\n",
       "    <g transform=\"translate(193.799343012 40.5133316929)scale(0.18 -0.18)\">\n",
       "     <use xlink:href=\"#BitstreamVeraSans-Roman-41\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"text_7\">\n",
       "    <!-- B -->\n",
       "    <g transform=\"translate(403.544841289 40.5133316929)scale(0.18 -0.18)\">\n",
       "     <use xlink:href=\"#BitstreamVeraSans-Roman-42\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"text_8\">\n",
       "    <!-- A -->\n",
       "    <g transform=\"translate(52.0670595472 40.5133316929)scale(0.18 -0.18)\">\n",
       "     <use xlink:href=\"#BitstreamVeraSans-Roman-41\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"text_9\">\n",
       "    <!-- C -->\n",
       "    <g transform=\"translate(227.687122293 85.8676624016)scale(0.18 -0.18)\">\n",
       "     <use xlink:href=\"#BitstreamVeraSans-Roman-43\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "  </g>\n",
       " </g>\n",
       " <defs>\n",
       "  <clipPath id=\"pe907e6a6b8\">\n",
       "   <rect height=\"113.385826772\" width=\"425.196850394\" x=\"7.2\" y=\"7.2\"/>\n",
       "  </clipPath>\n",
       " </defs>\n",
       "</svg>\n"
      ],
      "text/plain": [
       "<matplotlib.figure.Figure at 0x7feb96e2bf28>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "pgm = daft.PGM([7.5, 2], origin=[-0.5, 0.5])\n",
    "add_node(pgm, 'A', 'A', 0.4, 2)\n",
    "add_node(pgm, 'C', 'C', 1, 1.2)\n",
    "add_node(pgm, 'B', 'B', 1.6, 2)\n",
    "add_node(pgm, 'A2', 'A', 2.9, 2)\n",
    "add_node(pgm, 'C2', 'C', 3.5, 1.2)\n",
    "add_node(pgm, 'B2', 'B', 4.1, 2)\n",
    "add_node(pgm, 'A3', 'A', 5.4, 2)\n",
    "add_node(pgm, 'C3', 'C', 6, 1.2)\n",
    "add_node(pgm, 'B3', 'B', 6.6, 2)\n",
    "add_edges(pgm, [\n",
    "        ('C', 'A'),\n",
    "        ('C', 'B'),\n",
    "        ('C2', 'A2'),\n",
    "        ('B2', 'C2'),\n",
    "        ('A3', 'C3'),\n",
    "        ('C3', 'B3')\n",
    "    ])\n",
    "pgm.render()\n",
    "save('bn_prop_08')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {
    "collapsed": false,
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "image/svg+xml": [
       "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"no\"?>\n",
       "<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\n",
       "  \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n",
       "<!-- Created with matplotlib (http://matplotlib.org/) -->\n",
       "<svg height=\"241pt\" version=\"1.1\" viewBox=\"0 0 467 241\" width=\"467pt\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n",
       " <defs>\n",
       "  <style type=\"text/css\">\n",
       "*{stroke-linecap:butt;stroke-linejoin:round;stroke-miterlimit:100000;}\n",
       "  </style>\n",
       " </defs>\n",
       " <g id=\"figure_1\">\n",
       "  <g id=\"patch_1\">\n",
       "   <path d=\"M 0 241.171654 \n",
       "L 467.943307 241.171654 \n",
       "L 467.943307 -0 \n",
       "L 0 -0 \n",
       "L 0 241.171654 \n",
       "z\n",
       "\" style=\"fill:none;\"/>\n",
       "  </g>\n",
       "  <g id=\"axes_1\">\n",
       "   <g id=\"patch_2\">\n",
       "    <path clip-path=\"url(#p4fa18f8d63)\" d=\"M 148.932283 80.900787 \n",
       "C 153.442824 80.900787 157.769232 79.108731 160.958667 75.919296 \n",
       "C 164.148101 72.729862 165.940157 68.403454 165.940157 63.892913 \n",
       "C 165.940157 59.382372 164.148101 55.055964 160.958667 51.86653 \n",
       "C 157.769232 48.677096 153.442824 46.885039 148.932283 46.885039 \n",
       "C 144.421743 46.885039 140.095334 48.677096 136.9059 51.86653 \n",
       "C 133.716466 55.055964 131.924409 59.382372 131.924409 63.892913 \n",
       "C 131.924409 68.403454 133.716466 72.729862 136.9059 75.919296 \n",
       "C 140.095334 79.108731 144.421743 80.900787 148.932283 80.900787 \n",
       "L 148.932283 80.900787 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_3\">\n",
       "    <path clip-path=\"url(#p4fa18f8d63)\" d=\"M 347.35748 194.286614 \n",
       "C 351.868021 194.286614 356.194429 192.494557 359.383863 189.305123 \n",
       "C 362.573297 186.115689 364.365354 181.789281 364.365354 177.27874 \n",
       "C 364.365354 172.768199 362.573297 168.441791 359.383863 165.252357 \n",
       "C 356.194429 162.062923 351.868021 160.270866 347.35748 160.270866 \n",
       "C 342.846939 160.270866 338.520531 162.062923 335.331097 165.252357 \n",
       "C 332.141663 168.441791 330.349606 172.768199 330.349606 177.27874 \n",
       "C 330.349606 181.789281 332.141663 186.115689 335.331097 189.305123 \n",
       "C 338.520531 192.494557 342.846939 194.286614 347.35748 194.286614 \n",
       "L 347.35748 194.286614 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_4\">\n",
       "    <path clip-path=\"url(#p4fa18f8d63)\" d=\"M 92.23937 137.593701 \n",
       "C 96.749911 137.593701 101.076319 135.801644 104.265753 132.61221 \n",
       "C 107.455187 129.422776 109.247244 125.096368 109.247244 120.585827 \n",
       "C 109.247244 116.075286 107.455187 111.748878 104.265753 108.559444 \n",
       "C 101.076319 105.37001 96.749911 103.577953 92.23937 103.577953 \n",
       "C 87.728829 103.577953 83.402421 105.37001 80.212987 108.559444 \n",
       "C 77.023553 111.748878 75.231496 116.075286 75.231496 120.585827 \n",
       "C 75.231496 125.096368 77.023553 129.422776 80.212987 132.61221 \n",
       "C 83.402421 135.801644 87.728829 137.593701 92.23937 137.593701 \n",
       "L 92.23937 137.593701 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_5\">\n",
       "    <path clip-path=\"url(#p4fa18f8d63)\" d=\"M 35.546457 194.286614 \n",
       "C 40.056998 194.286614 44.383406 192.494557 47.57284 189.305123 \n",
       "C 50.762274 186.115689 52.554331 181.789281 52.554331 177.27874 \n",
       "C 52.554331 172.768199 50.762274 168.441791 47.57284 165.252357 \n",
       "C 44.383406 162.062923 40.056998 160.270866 35.546457 160.270866 \n",
       "C 31.035916 160.270866 26.709508 162.062923 23.520074 165.252357 \n",
       "C 20.33064 168.441791 18.538583 172.768199 18.538583 177.27874 \n",
       "C 18.538583 181.789281 20.33064 186.115689 23.520074 189.305123 \n",
       "C 26.709508 192.494557 31.035916 194.286614 35.546457 194.286614 \n",
       "L 35.546457 194.286614 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_6\">\n",
       "    <path clip-path=\"url(#p4fa18f8d63)\" d=\"M 233.971654 80.900787 \n",
       "C 238.482194 80.900787 242.808603 79.108731 245.998037 75.919296 \n",
       "C 249.187471 72.729862 250.979528 68.403454 250.979528 63.892913 \n",
       "C 250.979528 59.382372 249.187471 55.055964 245.998037 51.86653 \n",
       "C 242.808603 48.677096 238.482194 46.885039 233.971654 46.885039 \n",
       "C 229.461113 46.885039 225.134705 48.677096 221.94527 51.86653 \n",
       "C 218.755836 55.055964 216.96378 59.382372 216.96378 63.892913 \n",
       "C 216.96378 68.403454 218.755836 72.729862 221.94527 75.919296 \n",
       "C 225.134705 79.108731 229.461113 80.900787 233.971654 80.900787 \n",
       "L 233.971654 80.900787 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_7\">\n",
       "    <path clip-path=\"url(#p4fa18f8d63)\" d=\"M 35.546457 137.593701 \n",
       "C 40.056998 137.593701 44.383406 135.801644 47.57284 132.61221 \n",
       "C 50.762274 129.422776 52.554331 125.096368 52.554331 120.585827 \n",
       "C 52.554331 116.075286 50.762274 111.748878 47.57284 108.559444 \n",
       "C 44.383406 105.37001 40.056998 103.577953 35.546457 103.577953 \n",
       "C 31.035916 103.577953 26.709508 105.37001 23.520074 108.559444 \n",
       "C 20.33064 111.748878 18.538583 116.075286 18.538583 120.585827 \n",
       "C 18.538583 125.096368 20.33064 129.422776 23.520074 132.61221 \n",
       "C 26.709508 135.801644 31.035916 137.593701 35.546457 137.593701 \n",
       "L 35.546457 137.593701 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_8\">\n",
       "    <path clip-path=\"url(#p4fa18f8d63)\" d=\"M 347.35748 80.900787 \n",
       "C 351.868021 80.900787 356.194429 79.108731 359.383863 75.919296 \n",
       "C 362.573297 72.729862 364.365354 68.403454 364.365354 63.892913 \n",
       "C 364.365354 59.382372 362.573297 55.055964 359.383863 51.86653 \n",
       "C 356.194429 48.677096 351.868021 46.885039 347.35748 46.885039 \n",
       "C 342.846939 46.885039 338.520531 48.677096 335.331097 51.86653 \n",
       "C 332.141663 55.055964 330.349606 59.382372 330.349606 63.892913 \n",
       "C 330.349606 68.403454 332.141663 72.729862 335.331097 75.919296 \n",
       "C 338.520531 79.108731 342.846939 80.900787 347.35748 80.900787 \n",
       "L 347.35748 80.900787 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_9\">\n",
       "    <path clip-path=\"url(#p4fa18f8d63)\" d=\"M 92.23937 194.286614 \n",
       "C 96.749911 194.286614 101.076319 192.494557 104.265753 189.305123 \n",
       "C 107.455187 186.115689 109.247244 181.789281 109.247244 177.27874 \n",
       "C 109.247244 172.768199 107.455187 168.441791 104.265753 165.252357 \n",
       "C 101.076319 162.062923 96.749911 160.270866 92.23937 160.270866 \n",
       "C 87.728829 160.270866 83.402421 162.062923 80.212987 165.252357 \n",
       "C 77.023553 168.441791 75.231496 172.768199 75.231496 177.27874 \n",
       "C 75.231496 181.789281 77.023553 186.115689 80.212987 189.305123 \n",
       "C 83.402421 192.494557 87.728829 194.286614 92.23937 194.286614 \n",
       "L 92.23937 194.286614 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_10\">\n",
       "    <path clip-path=\"url(#p4fa18f8d63)\" d=\"M 233.971654 137.593701 \n",
       "C 238.482194 137.593701 242.808603 135.801644 245.998037 132.61221 \n",
       "C 249.187471 129.422776 250.979528 125.096368 250.979528 120.585827 \n",
       "C 250.979528 116.075286 249.187471 111.748878 245.998037 108.559444 \n",
       "C 242.808603 105.37001 238.482194 103.577953 233.971654 103.577953 \n",
       "C 229.461113 103.577953 225.134705 105.37001 221.94527 108.559444 \n",
       "C 218.755836 111.748878 216.96378 116.075286 216.96378 120.585827 \n",
       "C 216.96378 125.096368 218.755836 129.422776 221.94527 132.61221 \n",
       "C 225.134705 135.801644 229.461113 137.593701 233.971654 137.593701 \n",
       "L 233.971654 137.593701 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_11\">\n",
       "    <path clip-path=\"url(#p4fa18f8d63)\" d=\"M 233.971654 194.286614 \n",
       "C 238.482194 194.286614 242.808603 192.494557 245.998037 189.305123 \n",
       "C 249.187471 186.115689 250.979528 181.789281 250.979528 177.27874 \n",
       "C 250.979528 172.768199 249.187471 168.441791 245.998037 165.252357 \n",
       "C 242.808603 162.062923 238.482194 160.270866 233.971654 160.270866 \n",
       "C 229.461113 160.270866 225.134705 162.062923 221.94527 165.252357 \n",
       "C 218.755836 168.441791 216.96378 172.768199 216.96378 177.27874 \n",
       "C 216.96378 181.789281 218.755836 186.115689 221.94527 189.305123 \n",
       "C 225.134705 192.494557 229.461113 194.286614 233.971654 194.286614 \n",
       "L 233.971654 194.286614 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_12\">\n",
       "    <path clip-path=\"url(#p4fa18f8d63)\" d=\"M 148.932283 194.286614 \n",
       "C 153.442824 194.286614 157.769232 192.494557 160.958667 189.305123 \n",
       "C 164.148101 186.115689 165.940157 181.789281 165.940157 177.27874 \n",
       "C 165.940157 172.768199 164.148101 168.441791 160.958667 165.252357 \n",
       "C 157.769232 162.062923 153.442824 160.270866 148.932283 160.270866 \n",
       "C 144.421743 160.270866 140.095334 162.062923 136.9059 165.252357 \n",
       "C 133.716466 168.441791 131.924409 172.768199 131.924409 177.27874 \n",
       "C 131.924409 181.789281 133.716466 186.115689 136.9059 189.305123 \n",
       "C 140.095334 192.494557 144.421743 194.286614 148.932283 194.286614 \n",
       "L 148.932283 194.286614 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_13\">\n",
       "    <path clip-path=\"url(#p4fa18f8d63)\" d=\"M 35.546457 80.900787 \n",
       "C 40.056998 80.900787 44.383406 79.108731 47.57284 75.919296 \n",
       "C 50.762274 72.729862 52.554331 68.403454 52.554331 63.892913 \n",
       "C 52.554331 59.382372 50.762274 55.055964 47.57284 51.86653 \n",
       "C 44.383406 48.677096 40.056998 46.885039 35.546457 46.885039 \n",
       "C 31.035916 46.885039 26.709508 48.677096 23.520074 51.86653 \n",
       "C 20.33064 55.055964 18.538583 59.382372 18.538583 63.892913 \n",
       "C 18.538583 68.403454 20.33064 72.729862 23.520074 75.919296 \n",
       "C 26.709508 79.108731 31.035916 80.900787 35.546457 80.900787 \n",
       "L 35.546457 80.900787 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_14\">\n",
       "    <path clip-path=\"url(#p4fa18f8d63)\" d=\"M 92.23937 80.900787 \n",
       "C 96.749911 80.900787 101.076319 79.108731 104.265753 75.919296 \n",
       "C 107.455187 72.729862 109.247244 68.403454 109.247244 63.892913 \n",
       "C 109.247244 59.382372 107.455187 55.055964 104.265753 51.86653 \n",
       "C 101.076319 48.677096 96.749911 46.885039 92.23937 46.885039 \n",
       "C 87.728829 46.885039 83.402421 48.677096 80.212987 51.86653 \n",
       "C 77.023553 55.055964 75.231496 59.382372 75.231496 63.892913 \n",
       "C 75.231496 68.403454 77.023553 72.729862 80.212987 75.919296 \n",
       "C 83.402421 79.108731 87.728829 80.900787 92.23937 80.900787 \n",
       "L 92.23937 80.900787 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_15\">\n",
       "    <path clip-path=\"url(#p4fa18f8d63)\" d=\"M 290.664567 194.286614 \n",
       "C 295.175108 194.286614 299.501516 192.494557 302.69095 189.305123 \n",
       "C 305.880384 186.115689 307.672441 181.789281 307.672441 177.27874 \n",
       "C 307.672441 172.768199 305.880384 168.441791 302.69095 165.252357 \n",
       "C 299.501516 162.062923 295.175108 160.270866 290.664567 160.270866 \n",
       "C 286.154026 160.270866 281.827618 162.062923 278.638184 165.252357 \n",
       "C 275.44875 168.441791 273.656693 172.768199 273.656693 177.27874 \n",
       "C 273.656693 181.789281 275.44875 186.115689 278.638184 189.305123 \n",
       "C 281.827618 192.494557 286.154026 194.286614 290.664567 194.286614 \n",
       "L 290.664567 194.286614 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_16\">\n",
       "    <path clip-path=\"url(#p4fa18f8d63)\" d=\"M 290.664567 137.593701 \n",
       "C 295.175108 137.593701 299.501516 135.801644 302.69095 132.61221 \n",
       "C 305.880384 129.422776 307.672441 125.096368 307.672441 120.585827 \n",
       "C 307.672441 116.075286 305.880384 111.748878 302.69095 108.559444 \n",
       "C 299.501516 105.37001 295.175108 103.577953 290.664567 103.577953 \n",
       "C 286.154026 103.577953 281.827618 105.37001 278.638184 108.559444 \n",
       "C 275.44875 111.748878 273.656693 116.075286 273.656693 120.585827 \n",
       "C 273.656693 125.096368 275.44875 129.422776 278.638184 132.61221 \n",
       "C 281.827618 135.801644 286.154026 137.593701 290.664567 137.593701 \n",
       "L 290.664567 137.593701 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_17\">\n",
       "    <path clip-path=\"url(#p4fa18f8d63)\" d=\"M 148.932283 137.593701 \n",
       "C 153.442824 137.593701 157.769232 135.801644 160.958667 132.61221 \n",
       "C 164.148101 129.422776 165.940157 125.096368 165.940157 120.585827 \n",
       "C 165.940157 116.075286 164.148101 111.748878 160.958667 108.559444 \n",
       "C 157.769232 105.37001 153.442824 103.577953 148.932283 103.577953 \n",
       "C 144.421743 103.577953 140.095334 105.37001 136.9059 108.559444 \n",
       "C 133.716466 111.748878 131.924409 116.075286 131.924409 120.585827 \n",
       "C 131.924409 125.096368 133.716466 129.422776 136.9059 132.61221 \n",
       "C 140.095334 135.801644 144.421743 137.593701 148.932283 137.593701 \n",
       "L 148.932283 137.593701 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_18\">\n",
       "    <path clip-path=\"url(#p4fa18f8d63)\" d=\"M 347.35748 137.593701 \n",
       "C 351.868021 137.593701 356.194429 135.801644 359.383863 132.61221 \n",
       "C 362.573297 129.422776 364.365354 125.096368 364.365354 120.585827 \n",
       "C 364.365354 116.075286 362.573297 111.748878 359.383863 108.559444 \n",
       "C 356.194429 105.37001 351.868021 103.577953 347.35748 103.577953 \n",
       "C 342.846939 103.577953 338.520531 105.37001 335.331097 108.559444 \n",
       "C 332.141663 111.748878 330.349606 116.075286 330.349606 120.585827 \n",
       "C 330.349606 125.096368 332.141663 129.422776 335.331097 132.61221 \n",
       "C 338.520531 135.801644 342.846939 137.593701 347.35748 137.593701 \n",
       "L 347.35748 137.593701 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_19\">\n",
       "    <path clip-path=\"url(#p4fa18f8d63)\" d=\"M 290.664567 80.900787 \n",
       "C 295.175108 80.900787 299.501516 79.108731 302.69095 75.919296 \n",
       "C 305.880384 72.729862 307.672441 68.403454 307.672441 63.892913 \n",
       "C 307.672441 59.382372 305.880384 55.055964 302.69095 51.86653 \n",
       "C 299.501516 48.677096 295.175108 46.885039 290.664567 46.885039 \n",
       "C 286.154026 46.885039 281.827618 48.677096 278.638184 51.86653 \n",
       "C 275.44875 55.055964 273.656693 59.382372 273.656693 63.892913 \n",
       "C 273.656693 68.403454 275.44875 72.729862 278.638184 75.919296 \n",
       "C 281.827618 79.108731 286.154026 80.900787 290.664567 80.900787 \n",
       "L 290.664567 80.900787 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"line2d_1\">\n",
       "    <path clip-path=\"url(#p4fa18f8d63)\" d=\"M 52.554331 63.892913 \n",
       "L 75.231496 63.892913 \n",
       "\" style=\"fill:none;stroke:#000000;stroke-linecap:square;\"/>\n",
       "   </g>\n",
       "   <g id=\"line2d_2\">\n",
       "    <path clip-path=\"url(#p4fa18f8d63)\" d=\"M 109.247244 63.892913 \n",
       "L 131.924409 63.892913 \n",
       "\" style=\"fill:none;stroke:#000000;stroke-linecap:square;\"/>\n",
       "   </g>\n",
       "   <g id=\"line2d_3\">\n",
       "    <path clip-path=\"url(#p4fa18f8d63)\" d=\"M 35.546457 80.900787 \n",
       "L 35.546457 103.577953 \n",
       "\" style=\"fill:none;stroke:#000000;stroke-linecap:square;\"/>\n",
       "   </g>\n",
       "   <g id=\"line2d_4\">\n",
       "    <path clip-path=\"url(#p4fa18f8d63)\" d=\"M 92.23937 80.900787 \n",
       "L 92.23937 103.577953 \n",
       "\" style=\"fill:none;stroke:#000000;stroke-linecap:square;\"/>\n",
       "   </g>\n",
       "   <g id=\"line2d_5\">\n",
       "    <path clip-path=\"url(#p4fa18f8d63)\" d=\"M 148.932283 80.900787 \n",
       "L 148.932283 103.577953 \n",
       "\" style=\"fill:none;stroke:#000000;stroke-linecap:square;\"/>\n",
       "   </g>\n",
       "   <g id=\"line2d_6\">\n",
       "    <path clip-path=\"url(#p4fa18f8d63)\" d=\"M 52.554331 120.585827 \n",
       "L 75.231496 120.585827 \n",
       "\" style=\"fill:none;stroke:#000000;stroke-linecap:square;\"/>\n",
       "   </g>\n",
       "   <g id=\"line2d_7\">\n",
       "    <path clip-path=\"url(#p4fa18f8d63)\" d=\"M 109.247244 120.585827 \n",
       "L 131.924409 120.585827 \n",
       "\" style=\"fill:none;stroke:#000000;stroke-linecap:square;\"/>\n",
       "   </g>\n",
       "   <g id=\"line2d_8\">\n",
       "    <path clip-path=\"url(#p4fa18f8d63)\" d=\"M 35.546457 137.593701 \n",
       "L 35.546457 160.270866 \n",
       "\" style=\"fill:none;stroke:#000000;stroke-linecap:square;\"/>\n",
       "   </g>\n",
       "   <g id=\"line2d_9\">\n",
       "    <path clip-path=\"url(#p4fa18f8d63)\" d=\"M 92.23937 137.593701 \n",
       "L 92.23937 160.270866 \n",
       "\" style=\"fill:none;stroke:#000000;stroke-linecap:square;\"/>\n",
       "   </g>\n",
       "   <g id=\"line2d_10\">\n",
       "    <path clip-path=\"url(#p4fa18f8d63)\" d=\"M 148.932283 137.593701 \n",
       "L 148.932283 160.270866 \n",
       "\" style=\"fill:none;stroke:#000000;stroke-linecap:square;\"/>\n",
       "   </g>\n",
       "   <g id=\"line2d_11\">\n",
       "    <path clip-path=\"url(#p4fa18f8d63)\" d=\"M 52.554331 177.27874 \n",
       "L 75.231496 177.27874 \n",
       "\" style=\"fill:none;stroke:#000000;stroke-linecap:square;\"/>\n",
       "   </g>\n",
       "   <g id=\"line2d_12\">\n",
       "    <path clip-path=\"url(#p4fa18f8d63)\" d=\"M 109.247244 177.27874 \n",
       "L 131.924409 177.27874 \n",
       "\" style=\"fill:none;stroke:#000000;stroke-linecap:square;\"/>\n",
       "   </g>\n",
       "   <g id=\"line2d_13\">\n",
       "    <path clip-path=\"url(#p4fa18f8d63)\" d=\"M 250.979528 63.892913 \n",
       "L 273.656693 63.892913 \n",
       "\" style=\"fill:none;stroke:#000000;stroke-linecap:square;\"/>\n",
       "   </g>\n",
       "   <g id=\"line2d_14\">\n",
       "    <path clip-path=\"url(#p4fa18f8d63)\" d=\"M 307.672441 63.892913 \n",
       "L 330.349606 63.892913 \n",
       "\" style=\"fill:none;stroke:#000000;stroke-linecap:square;\"/>\n",
       "   </g>\n",
       "   <g id=\"line2d_15\">\n",
       "    <path clip-path=\"url(#p4fa18f8d63)\" d=\"M 290.664567 80.900787 \n",
       "L 290.664567 103.577953 \n",
       "\" style=\"fill:none;stroke:#000000;stroke-linecap:square;\"/>\n",
       "   </g>\n",
       "   <g id=\"line2d_16\">\n",
       "    <path clip-path=\"url(#p4fa18f8d63)\" d=\"M 250.979528 120.585827 \n",
       "L 273.656693 120.585827 \n",
       "\" style=\"fill:none;stroke:#000000;stroke-linecap:square;\"/>\n",
       "   </g>\n",
       "   <g id=\"line2d_17\">\n",
       "    <path clip-path=\"url(#p4fa18f8d63)\" d=\"M 233.971654 137.593701 \n",
       "L 233.971654 160.270866 \n",
       "\" style=\"fill:none;stroke:#000000;stroke-linecap:square;\"/>\n",
       "   </g>\n",
       "   <g id=\"line2d_18\">\n",
       "    <path clip-path=\"url(#p4fa18f8d63)\" d=\"M 250.979528 177.27874 \n",
       "L 273.656693 177.27874 \n",
       "\" style=\"fill:none;stroke:#000000;stroke-linecap:square;\"/>\n",
       "   </g>\n",
       "   <g id=\"line2d_19\">\n",
       "    <path clip-path=\"url(#p4fa18f8d63)\" d=\"M 307.672441 177.27874 \n",
       "L 330.349606 177.27874 \n",
       "\" style=\"fill:none;stroke:#000000;stroke-linecap:square;\"/>\n",
       "   </g>\n",
       "   <g id=\"line2d_20\">\n",
       "    <path clip-path=\"url(#p4fa18f8d63)\" d=\"M 347.35748 160.270866 \n",
       "L 347.35748 137.593701 \n",
       "\" style=\"fill:none;stroke:#000000;stroke-linecap:square;\"/>\n",
       "   </g>\n",
       "   <g id=\"matplotlib.axis_1\"/>\n",
       "   <g id=\"matplotlib.axis_2\"/>\n",
       "   <g id=\"text_1\">\n",
       "    <!-- C -->\n",
       "    <defs>\n",
       "     <path d=\"M 64.40625 67.28125 \n",
       "L 64.40625 56.890625 \n",
       "Q 59.421875 61.53125 53.78125 63.8125 \n",
       "Q 48.140625 66.109375 41.796875 66.109375 \n",
       "Q 29.296875 66.109375 22.65625 58.46875 \n",
       "Q 16.015625 50.828125 16.015625 36.375 \n",
       "Q 16.015625 21.96875 22.65625 14.328125 \n",
       "Q 29.296875 6.6875 41.796875 6.6875 \n",
       "Q 48.140625 6.6875 53.78125 8.984375 \n",
       "Q 59.421875 11.28125 64.40625 15.921875 \n",
       "L 64.40625 5.609375 \n",
       "Q 59.234375 2.09375 53.4375 0.328125 \n",
       "Q 47.65625 -1.421875 41.21875 -1.421875 \n",
       "Q 24.65625 -1.421875 15.125 8.703125 \n",
       "Q 5.609375 18.84375 5.609375 36.375 \n",
       "Q 5.609375 53.953125 15.125 64.078125 \n",
       "Q 24.65625 74.21875 41.21875 74.21875 \n",
       "Q 47.75 74.21875 53.53125 72.484375 \n",
       "Q 59.328125 70.75 64.40625 67.28125 \n",
       "\" id=\"BitstreamVeraSans-Roman-43\"/>\n",
       "    </defs>\n",
       "    <g transform=\"translate(142.647752215 68.8597883858)scale(0.18 -0.18)\">\n",
       "     <use xlink:href=\"#BitstreamVeraSans-Roman-43\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"text_2\">\n",
       "    <!-- I -->\n",
       "    <defs>\n",
       "     <path d=\"M 9.8125 72.90625 \n",
       "L 19.671875 72.90625 \n",
       "L 19.671875 0 \n",
       "L 9.8125 0 \n",
       "z\n",
       "\" id=\"BitstreamVeraSans-Roman-49\"/>\n",
       "    </defs>\n",
       "    <g transform=\"translate(344.702480315 182.245615157)scale(0.18 -0.18)\">\n",
       "     <use xlink:href=\"#BitstreamVeraSans-Roman-49\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"text_3\">\n",
       "    <!-- E -->\n",
       "    <defs>\n",
       "     <path d=\"M 9.8125 72.90625 \n",
       "L 55.90625 72.90625 \n",
       "L 55.90625 64.59375 \n",
       "L 19.671875 64.59375 \n",
       "L 19.671875 43.015625 \n",
       "L 54.390625 43.015625 \n",
       "L 54.390625 34.71875 \n",
       "L 19.671875 34.71875 \n",
       "L 19.671875 8.296875 \n",
       "L 56.78125 8.296875 \n",
       "L 56.78125 0 \n",
       "L 9.8125 0 \n",
       "z\n",
       "\" id=\"BitstreamVeraSans-Roman-45\"/>\n",
       "    </defs>\n",
       "    <g transform=\"translate(86.5524950787 125.552701772)scale(0.18 -0.18)\">\n",
       "     <use xlink:href=\"#BitstreamVeraSans-Roman-45\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"text_4\">\n",
       "    <!-- G -->\n",
       "    <defs>\n",
       "     <path d=\"M 59.515625 10.40625 \n",
       "L 59.515625 29.984375 \n",
       "L 43.40625 29.984375 \n",
       "L 43.40625 38.09375 \n",
       "L 69.28125 38.09375 \n",
       "L 69.28125 6.78125 \n",
       "Q 63.578125 2.734375 56.6875 0.65625 \n",
       "Q 49.8125 -1.421875 42 -1.421875 \n",
       "Q 24.90625 -1.421875 15.25 8.5625 \n",
       "Q 5.609375 18.5625 5.609375 36.375 \n",
       "Q 5.609375 54.25 15.25 64.234375 \n",
       "Q 24.90625 74.21875 42 74.21875 \n",
       "Q 49.125 74.21875 55.546875 72.453125 \n",
       "Q 61.96875 70.703125 67.390625 67.28125 \n",
       "L 67.390625 56.78125 \n",
       "Q 61.921875 61.421875 55.765625 63.765625 \n",
       "Q 49.609375 66.109375 42.828125 66.109375 \n",
       "Q 29.4375 66.109375 22.71875 58.640625 \n",
       "Q 16.015625 51.171875 16.015625 36.375 \n",
       "Q 16.015625 21.625 22.71875 14.15625 \n",
       "Q 29.4375 6.6875 42.828125 6.6875 \n",
       "Q 48.046875 6.6875 52.140625 7.59375 \n",
       "Q 56.25 8.5 59.515625 10.40625 \n",
       "\" id=\"BitstreamVeraSans-Roman-47\"/>\n",
       "    </defs>\n",
       "    <g transform=\"translate(28.5728629429 182.245615157)scale(0.18 -0.18)\">\n",
       "     <use xlink:href=\"#BitstreamVeraSans-Roman-47\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"text_5\">\n",
       "    <!-- A -->\n",
       "    <defs>\n",
       "     <path d=\"M 34.1875 63.1875 \n",
       "L 20.796875 26.90625 \n",
       "L 47.609375 26.90625 \n",
       "z\n",
       "M 28.609375 72.90625 \n",
       "L 39.796875 72.90625 \n",
       "L 67.578125 0 \n",
       "L 57.328125 0 \n",
       "L 50.6875 18.703125 \n",
       "L 17.828125 18.703125 \n",
       "L 11.1875 0 \n",
       "L 0.78125 0 \n",
       "z\n",
       "\" id=\"BitstreamVeraSans-Roman-41\"/>\n",
       "    </defs>\n",
       "    <g transform=\"translate(227.815091043 68.8597883858)scale(0.18 -0.18)\">\n",
       "     <use xlink:href=\"#BitstreamVeraSans-Roman-41\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"text_6\">\n",
       "    <!-- D -->\n",
       "    <defs>\n",
       "     <path d=\"M 19.671875 64.796875 \n",
       "L 19.671875 8.109375 \n",
       "L 31.59375 8.109375 \n",
       "Q 46.6875 8.109375 53.6875 14.9375 \n",
       "Q 60.6875 21.78125 60.6875 36.53125 \n",
       "Q 60.6875 51.171875 53.6875 57.984375 \n",
       "Q 46.6875 64.796875 31.59375 64.796875 \n",
       "z\n",
       "M 9.8125 72.90625 \n",
       "L 30.078125 72.90625 \n",
       "Q 51.265625 72.90625 61.171875 64.09375 \n",
       "Q 71.09375 55.28125 71.09375 36.53125 \n",
       "Q 71.09375 17.671875 61.125 8.828125 \n",
       "Q 51.171875 0 30.078125 0 \n",
       "L 9.8125 0 \n",
       "z\n",
       "\" id=\"BitstreamVeraSans-Roman-44\"/>\n",
       "    </defs>\n",
       "    <g transform=\"translate(28.6164566929 125.552701772)scale(0.18 -0.18)\">\n",
       "     <use xlink:href=\"#BitstreamVeraSans-Roman-44\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"text_7\">\n",
       "    <!-- C -->\n",
       "    <g transform=\"translate(341.072949065 68.8597883858)scale(0.18 -0.18)\">\n",
       "     <use xlink:href=\"#BitstreamVeraSans-Roman-43\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"text_8\">\n",
       "    <!-- H -->\n",
       "    <defs>\n",
       "     <path d=\"M 9.8125 72.90625 \n",
       "L 19.671875 72.90625 \n",
       "L 19.671875 43.015625 \n",
       "L 55.515625 43.015625 \n",
       "L 55.515625 72.90625 \n",
       "L 65.375 72.90625 \n",
       "L 65.375 0 \n",
       "L 55.515625 0 \n",
       "L 55.515625 34.71875 \n",
       "L 19.671875 34.71875 \n",
       "L 19.671875 0 \n",
       "L 9.8125 0 \n",
       "z\n",
       "\" id=\"BitstreamVeraSans-Roman-48\"/>\n",
       "    </defs>\n",
       "    <g transform=\"translate(85.4710888287 182.245615157)scale(0.18 -0.18)\">\n",
       "     <use xlink:href=\"#BitstreamVeraSans-Roman-48\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"text_9\">\n",
       "    <!-- D -->\n",
       "    <g transform=\"translate(227.041653543 125.552701772)scale(0.18 -0.18)\">\n",
       "     <use xlink:href=\"#BitstreamVeraSans-Roman-44\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"text_10\">\n",
       "    <!-- G -->\n",
       "    <g transform=\"translate(226.998059793 182.245615157)scale(0.18 -0.18)\">\n",
       "     <use xlink:href=\"#BitstreamVeraSans-Roman-47\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"text_11\">\n",
       "    <!-- I -->\n",
       "    <g transform=\"translate(146.277283465 182.245615157)scale(0.18 -0.18)\">\n",
       "     <use xlink:href=\"#BitstreamVeraSans-Roman-49\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"text_12\">\n",
       "    <!-- A -->\n",
       "    <g transform=\"translate(29.3898941929 68.8597883858)scale(0.18 -0.18)\">\n",
       "     <use xlink:href=\"#BitstreamVeraSans-Roman-41\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"text_13\">\n",
       "    <!-- B -->\n",
       "    <defs>\n",
       "     <path d=\"M 19.671875 34.8125 \n",
       "L 19.671875 8.109375 \n",
       "L 35.5 8.109375 \n",
       "Q 43.453125 8.109375 47.28125 11.40625 \n",
       "Q 51.125 14.703125 51.125 21.484375 \n",
       "Q 51.125 28.328125 47.28125 31.5625 \n",
       "Q 43.453125 34.8125 35.5 34.8125 \n",
       "z\n",
       "M 19.671875 64.796875 \n",
       "L 19.671875 42.828125 \n",
       "L 34.28125 42.828125 \n",
       "Q 41.5 42.828125 45.03125 45.53125 \n",
       "Q 48.578125 48.25 48.578125 53.8125 \n",
       "Q 48.578125 59.328125 45.03125 62.0625 \n",
       "Q 41.5 64.796875 34.28125 64.796875 \n",
       "z\n",
       "M 9.8125 72.90625 \n",
       "L 35.015625 72.90625 \n",
       "Q 46.296875 72.90625 52.390625 68.21875 \n",
       "Q 58.5 63.53125 58.5 54.890625 \n",
       "Q 58.5 48.1875 55.375 44.234375 \n",
       "Q 52.25 40.28125 46.1875 39.3125 \n",
       "Q 53.46875 37.75 57.5 32.78125 \n",
       "Q 61.53125 27.828125 61.53125 20.40625 \n",
       "Q 61.53125 10.640625 54.890625 5.3125 \n",
       "Q 48.25 0 35.984375 0 \n",
       "L 9.8125 0 \n",
       "z\n",
       "\" id=\"BitstreamVeraSans-Roman-42\"/>\n",
       "    </defs>\n",
       "    <g transform=\"translate(86.0645263287 68.8597883858)scale(0.18 -0.18)\">\n",
       "     <use xlink:href=\"#BitstreamVeraSans-Roman-42\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"text_14\">\n",
       "    <!-- H -->\n",
       "    <g transform=\"translate(283.896285679 182.245615157)scale(0.18 -0.18)\">\n",
       "     <use xlink:href=\"#BitstreamVeraSans-Roman-48\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"text_15\">\n",
       "    <!-- E -->\n",
       "    <g transform=\"translate(284.977691929 125.552701772)scale(0.18 -0.18)\">\n",
       "     <use xlink:href=\"#BitstreamVeraSans-Roman-45\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"text_16\">\n",
       "    <!-- F -->\n",
       "    <defs>\n",
       "     <path d=\"M 9.8125 72.90625 \n",
       "L 51.703125 72.90625 \n",
       "L 51.703125 64.59375 \n",
       "L 19.671875 64.59375 \n",
       "L 19.671875 43.109375 \n",
       "L 48.578125 43.109375 \n",
       "L 48.578125 34.8125 \n",
       "L 19.671875 34.8125 \n",
       "L 19.671875 0 \n",
       "L 9.8125 0 \n",
       "z\n",
       "\" id=\"BitstreamVeraSans-Roman-46\"/>\n",
       "    </defs>\n",
       "    <g transform=\"translate(143.755877215 125.552701772)scale(0.18 -0.18)\">\n",
       "     <use xlink:href=\"#BitstreamVeraSans-Roman-46\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"text_17\">\n",
       "    <!-- F -->\n",
       "    <g transform=\"translate(342.181074065 125.552701772)scale(0.18 -0.18)\">\n",
       "     <use xlink:href=\"#BitstreamVeraSans-Roman-46\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"text_18\">\n",
       "    <!-- B -->\n",
       "    <g transform=\"translate(284.489723179 68.8597883858)scale(0.18 -0.18)\">\n",
       "     <use xlink:href=\"#BitstreamVeraSans-Roman-42\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "  </g>\n",
       " </g>\n",
       " <defs>\n",
       "  <clipPath id=\"p4fa18f8d63\">\n",
       "   <rect height=\"226.771653543\" width=\"453.543307087\" x=\"7.2\" y=\"7.2\"/>\n",
       "  </clipPath>\n",
       " </defs>\n",
       "</svg>\n"
      ],
      "text/plain": [
       "<matplotlib.figure.Figure at 0x7feb96adc748>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "pgm = daft.PGM([8, 4], origin=[-0.5, 0.5], directed=False)\n",
    "add_node(pgm, 'A', 'A', 0, 3.5)\n",
    "add_node(pgm, 'B', 'B', 1, 3.5)\n",
    "add_node(pgm, 'C', 'C', 2, 3.5)\n",
    "add_node(pgm, 'D', 'D', 0, 2.5)\n",
    "add_node(pgm, 'E', 'E', 1, 2.5)\n",
    "add_node(pgm, 'F', 'F', 2, 2.5)\n",
    "add_node(pgm, 'G', 'G', 0, 1.5)\n",
    "add_node(pgm, 'H', 'H', 1, 1.5)\n",
    "add_node(pgm, 'I', 'I', 2, 1.5)\n",
    "\n",
    "add_edges(pgm, [\n",
    "        ('A', 'B'),\n",
    "        ('B', 'C'),\n",
    "        ('A', 'D'),\n",
    "        ('B', 'E'),\n",
    "        ('C', 'F'),\n",
    "        ('D', 'E'),\n",
    "        ('E', 'F'),\n",
    "        ('D', 'G'),\n",
    "        ('E', 'H'),\n",
    "        ('F', 'I'),\n",
    "        ('G', 'H'),\n",
    "        ('H', 'I')\n",
    "    ])\n",
    "\n",
    "add_node(pgm, 'A2', 'A', 3.5, 3.5)\n",
    "add_node(pgm, 'B2', 'B', 4.5, 3.5)\n",
    "add_node(pgm, 'C2', 'C', 5.5, 3.5)\n",
    "add_node(pgm, 'D2', 'D', 3.5, 2.5)\n",
    "add_node(pgm, 'E2', 'E', 4.5, 2.5)\n",
    "add_node(pgm, 'F2', 'F', 5.5, 2.5)\n",
    "add_node(pgm, 'G2', 'G', 3.5, 1.5)\n",
    "add_node(pgm, 'H2', 'H', 4.5, 1.5)\n",
    "add_node(pgm, 'I2', 'I', 5.5, 1.5)\n",
    "\n",
    "add_edges(pgm, [\n",
    "        ('A2', 'B2'),\n",
    "        ('B2', 'C2'),\n",
    "        ('B2', 'E2'),\n",
    "        ('D2', 'E2'),\n",
    "        ('D2', 'G2'),\n",
    "        ('G2', 'H2'),\n",
    "        ('H2', 'I2'),\n",
    "        ('I2', 'F2'),\n",
    "    ])\n",
    "pgm.render()\n",
    "save('spanning_tree')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "image/svg+xml": [
       "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"no\"?>\n",
       "<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\n",
       "  \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n",
       "<!-- Created with matplotlib (http://matplotlib.org/) -->\n",
       "<svg height=\"184pt\" version=\"1.1\" viewBox=\"0 0 241 184\" width=\"241pt\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n",
       " <defs>\n",
       "  <style type=\"text/css\">\n",
       "*{stroke-linecap:butt;stroke-linejoin:round;stroke-miterlimit:100000;}\n",
       "  </style>\n",
       " </defs>\n",
       " <g id=\"figure_1\">\n",
       "  <g id=\"patch_1\">\n",
       "   <path d=\"M 0 184.47874 \n",
       "L 241.171654 184.47874 \n",
       "L 241.171654 0 \n",
       "L 0 0 \n",
       "L 0 184.47874 \n",
       "z\n",
       "\" style=\"fill:none;\"/>\n",
       "  </g>\n",
       "  <g id=\"axes_1\">\n",
       "   <g id=\"patch_2\">\n",
       "    <path clip-path=\"url(#p50c4854f71)\" d=\"M 82.034646 67.294488 \n",
       "L 78.633071 66.302362 \n",
       "L 80.333858 65.026772 \n",
       "L 68.428346 49.152756 \n",
       "L 68.428346 49.152756 \n",
       "L 80.333858 65.026772 \n",
       "L 82.034646 63.751181 \n",
       "L 82.034646 67.294488 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_3\">\n",
       "    <path clip-path=\"url(#p50c4854f71)\" d=\"M 102.444094 67.294488 \n",
       "L 102.444094 63.751181 \n",
       "L 104.144882 65.026772 \n",
       "L 116.050394 49.152756 \n",
       "L 116.050394 49.152756 \n",
       "L 104.144882 65.026772 \n",
       "L 105.845669 66.302362 \n",
       "L 102.444094 67.294488 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_4\">\n",
       "    <path clip-path=\"url(#p50c4854f71)\" d=\"M 150.066142 67.294488 \n",
       "L 146.664567 66.302362 \n",
       "L 148.365354 65.026772 \n",
       "L 136.459843 49.152756 \n",
       "L 136.459843 49.152756 \n",
       "L 148.365354 65.026772 \n",
       "L 150.066142 63.751181 \n",
       "L 150.066142 67.294488 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_5\">\n",
       "    <path clip-path=\"url(#p50c4854f71)\" d=\"M 92.23937 120.585827 \n",
       "L 90.113386 117.751181 \n",
       "L 92.23937 117.751181 \n",
       "L 92.23937 97.908661 \n",
       "L 92.23937 97.908661 \n",
       "L 92.23937 117.751181 \n",
       "L 94.365354 117.751181 \n",
       "L 92.23937 120.585827 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_6\">\n",
       "    <path clip-path=\"url(#p50c4854f71)\" d=\"M 58.223622 52.554331 \n",
       "C 62.734163 52.554331 67.060571 50.762274 70.250005 47.57284 \n",
       "C 73.439439 44.383406 75.231496 40.056998 75.231496 35.546457 \n",
       "C 75.231496 31.035916 73.439439 26.709508 70.250005 23.520074 \n",
       "C 67.060571 20.33064 62.734163 18.538583 58.223622 18.538583 \n",
       "C 53.713081 18.538583 49.386673 20.33064 46.197239 23.520074 \n",
       "C 43.007805 26.709508 41.215748 31.035916 41.215748 35.546457 \n",
       "C 41.215748 40.056998 43.007805 44.383406 46.197239 47.57284 \n",
       "C 49.386673 50.762274 53.713081 52.554331 58.223622 52.554331 \n",
       "L 58.223622 52.554331 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_7\">\n",
       "    <path clip-path=\"url(#p50c4854f71)\" d=\"M 126.255118 52.554331 \n",
       "C 130.765659 52.554331 135.092067 50.762274 138.281501 47.57284 \n",
       "C 141.470935 44.383406 143.262992 40.056998 143.262992 35.546457 \n",
       "C 143.262992 31.035916 141.470935 26.709508 138.281501 23.520074 \n",
       "C 135.092067 20.33064 130.765659 18.538583 126.255118 18.538583 \n",
       "C 121.744577 18.538583 117.418169 20.33064 114.228735 23.520074 \n",
       "C 111.039301 26.709508 109.247244 31.035916 109.247244 35.546457 \n",
       "C 109.247244 40.056998 111.039301 44.383406 114.228735 47.57284 \n",
       "C 117.418169 50.762274 121.744577 52.554331 126.255118 52.554331 \n",
       "L 126.255118 52.554331 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_8\">\n",
       "    <path clip-path=\"url(#p50c4854f71)\" d=\"M 92.23937 154.601575 \n",
       "C 96.749911 154.601575 101.076319 152.809518 104.265753 149.620084 \n",
       "C 107.455187 146.43065 109.247244 142.104242 109.247244 137.593701 \n",
       "C 109.247244 133.08316 107.455187 128.756752 104.265753 125.567318 \n",
       "C 101.076319 122.377884 96.749911 120.585827 92.23937 120.585827 \n",
       "C 87.728829 120.585827 83.402421 122.377884 80.212987 125.567318 \n",
       "C 77.023553 128.756752 75.231496 133.08316 75.231496 137.593701 \n",
       "C 75.231496 142.104242 77.023553 146.43065 80.212987 149.620084 \n",
       "C 83.402421 152.809518 87.728829 154.601575 92.23937 154.601575 \n",
       "L 92.23937 154.601575 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_9\">\n",
       "    <path clip-path=\"url(#p50c4854f71)\" d=\"M 160.270866 97.908661 \n",
       "C 164.781407 97.908661 169.107815 96.116605 172.297249 92.92717 \n",
       "C 175.486683 89.737736 177.27874 85.411328 177.27874 80.900787 \n",
       "C 177.27874 76.390246 175.486683 72.063838 172.297249 68.874404 \n",
       "C 169.107815 65.68497 164.781407 63.892913 160.270866 63.892913 \n",
       "C 155.760325 63.892913 151.433917 65.68497 148.244483 68.874404 \n",
       "C 145.055049 72.063838 143.262992 76.390246 143.262992 80.900787 \n",
       "C 143.262992 85.411328 145.055049 89.737736 148.244483 92.92717 \n",
       "C 151.433917 96.116605 155.760325 97.908661 160.270866 97.908661 \n",
       "L 160.270866 97.908661 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_10\">\n",
       "    <path clip-path=\"url(#p50c4854f71)\" d=\"M 92.23937 97.908661 \n",
       "C 96.749911 97.908661 101.076319 96.116605 104.265753 92.92717 \n",
       "C 107.455187 89.737736 109.247244 85.411328 109.247244 80.900787 \n",
       "C 109.247244 76.390246 107.455187 72.063838 104.265753 68.874404 \n",
       "C 101.076319 65.68497 96.749911 63.892913 92.23937 63.892913 \n",
       "C 87.728829 63.892913 83.402421 65.68497 80.212987 68.874404 \n",
       "C 77.023553 72.063838 75.231496 76.390246 75.231496 80.900787 \n",
       "C 75.231496 85.411328 77.023553 89.737736 80.212987 92.92717 \n",
       "C 83.402421 96.116605 87.728829 97.908661 92.23937 97.908661 \n",
       "L 92.23937 97.908661 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"matplotlib.axis_1\"/>\n",
       "   <g id=\"matplotlib.axis_2\"/>\n",
       "   <g id=\"text_1\">\n",
       "    <!-- D -->\n",
       "    <defs>\n",
       "     <path d=\"M 19.671875 64.796875 \n",
       "L 19.671875 8.109375 \n",
       "L 31.59375 8.109375 \n",
       "Q 46.6875 8.109375 53.6875 14.9375 \n",
       "Q 60.6875 21.78125 60.6875 36.53125 \n",
       "Q 60.6875 51.171875 53.6875 57.984375 \n",
       "Q 46.6875 64.796875 31.59375 64.796875 \n",
       "z\n",
       "M 9.8125 72.90625 \n",
       "L 30.078125 72.90625 \n",
       "Q 51.265625 72.90625 61.171875 64.09375 \n",
       "Q 71.09375 55.28125 71.09375 36.53125 \n",
       "Q 71.09375 17.671875 61.125 8.828125 \n",
       "Q 51.171875 0 30.078125 0 \n",
       "L 9.8125 0 \n",
       "z\n",
       "\" id=\"BitstreamVeraSans-Roman-44\"/>\n",
       "    </defs>\n",
       "    <g transform=\"translate(51.2936220472 40.5133316929)scale(0.18 -0.18)\">\n",
       "     <use xlink:href=\"#BitstreamVeraSans-Roman-44\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"text_2\">\n",
       "    <!-- I -->\n",
       "    <defs>\n",
       "     <path d=\"M 9.8125 72.90625 \n",
       "L 19.671875 72.90625 \n",
       "L 19.671875 0 \n",
       "L 9.8125 0 \n",
       "z\n",
       "\" id=\"BitstreamVeraSans-Roman-49\"/>\n",
       "    </defs>\n",
       "    <g transform=\"translate(123.60011811 40.5133316929)scale(0.18 -0.18)\">\n",
       "     <use xlink:href=\"#BitstreamVeraSans-Roman-49\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"text_3\">\n",
       "    <!-- L -->\n",
       "    <defs>\n",
       "     <path d=\"M 9.8125 72.90625 \n",
       "L 19.671875 72.90625 \n",
       "L 19.671875 8.296875 \n",
       "L 55.171875 8.296875 \n",
       "L 55.171875 0 \n",
       "L 9.8125 0 \n",
       "z\n",
       "\" id=\"BitstreamVeraSans-Roman-4c\"/>\n",
       "    </defs>\n",
       "    <g transform=\"translate(87.2246825787 142.560575787)scale(0.18 -0.18)\">\n",
       "     <use xlink:href=\"#BitstreamVeraSans-Roman-4c\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"text_4\">\n",
       "    <!-- S -->\n",
       "    <defs>\n",
       "     <path d=\"M 53.515625 70.515625 \n",
       "L 53.515625 60.890625 \n",
       "Q 47.90625 63.578125 42.921875 64.890625 \n",
       "Q 37.9375 66.21875 33.296875 66.21875 \n",
       "Q 25.25 66.21875 20.875 63.09375 \n",
       "Q 16.5 59.96875 16.5 54.203125 \n",
       "Q 16.5 49.359375 19.40625 46.890625 \n",
       "Q 22.3125 44.4375 30.421875 42.921875 \n",
       "L 36.375 41.703125 \n",
       "Q 47.40625 39.59375 52.65625 34.296875 \n",
       "Q 57.90625 29 57.90625 20.125 \n",
       "Q 57.90625 9.515625 50.796875 4.046875 \n",
       "Q 43.703125 -1.421875 29.984375 -1.421875 \n",
       "Q 24.8125 -1.421875 18.96875 -0.25 \n",
       "Q 13.140625 0.921875 6.890625 3.21875 \n",
       "L 6.890625 13.375 \n",
       "Q 12.890625 10.015625 18.65625 8.296875 \n",
       "Q 24.421875 6.59375 29.984375 6.59375 \n",
       "Q 38.421875 6.59375 43.015625 9.90625 \n",
       "Q 47.609375 13.234375 47.609375 19.390625 \n",
       "Q 47.609375 24.75 44.3125 27.78125 \n",
       "Q 41.015625 30.8125 33.5 32.328125 \n",
       "L 27.484375 33.5 \n",
       "Q 16.453125 35.6875 11.515625 40.375 \n",
       "Q 6.59375 45.0625 6.59375 53.421875 \n",
       "Q 6.59375 63.09375 13.40625 68.65625 \n",
       "Q 20.21875 74.21875 32.171875 74.21875 \n",
       "Q 37.3125 74.21875 42.625 73.28125 \n",
       "Q 47.953125 72.359375 53.515625 70.515625 \n",
       "\" id=\"BitstreamVeraSans-Roman-53\"/>\n",
       "    </defs>\n",
       "    <g transform=\"translate(154.557272392 85.8676624016)scale(0.18 -0.18)\">\n",
       "     <use xlink:href=\"#BitstreamVeraSans-Roman-53\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"text_5\">\n",
       "    <!-- G -->\n",
       "    <defs>\n",
       "     <path d=\"M 59.515625 10.40625 \n",
       "L 59.515625 29.984375 \n",
       "L 43.40625 29.984375 \n",
       "L 43.40625 38.09375 \n",
       "L 69.28125 38.09375 \n",
       "L 69.28125 6.78125 \n",
       "Q 63.578125 2.734375 56.6875 0.65625 \n",
       "Q 49.8125 -1.421875 42 -1.421875 \n",
       "Q 24.90625 -1.421875 15.25 8.5625 \n",
       "Q 5.609375 18.5625 5.609375 36.375 \n",
       "Q 5.609375 54.25 15.25 64.234375 \n",
       "Q 24.90625 74.21875 42 74.21875 \n",
       "Q 49.125 74.21875 55.546875 72.453125 \n",
       "Q 61.96875 70.703125 67.390625 67.28125 \n",
       "L 67.390625 56.78125 \n",
       "Q 61.921875 61.421875 55.765625 63.765625 \n",
       "Q 49.609375 66.109375 42.828125 66.109375 \n",
       "Q 29.4375 66.109375 22.71875 58.640625 \n",
       "Q 16.015625 51.171875 16.015625 36.375 \n",
       "Q 16.015625 21.625 22.71875 14.15625 \n",
       "Q 29.4375 6.6875 42.828125 6.6875 \n",
       "Q 48.046875 6.6875 52.140625 7.59375 \n",
       "Q 56.25 8.5 59.515625 10.40625 \n",
       "\" id=\"BitstreamVeraSans-Roman-47\"/>\n",
       "    </defs>\n",
       "    <g transform=\"translate(85.2657763287 85.8676624016)scale(0.18 -0.18)\">\n",
       "     <use xlink:href=\"#BitstreamVeraSans-Roman-47\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "  </g>\n",
       " </g>\n",
       " <defs>\n",
       "  <clipPath id=\"p50c4854f71\">\n",
       "   <rect height=\"170.078740157\" width=\"226.771653543\" x=\"7.2\" y=\"7.2\"/>\n",
       "  </clipPath>\n",
       " </defs>\n",
       "</svg>\n"
      ],
      "text/plain": [
       "<matplotlib.figure.Figure at 0x7feb96a41908>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "pgm = daft.PGM([4, 3], origin=[-0.5, 0.5])\n",
    "add_node(pgm, 'D', 'D', 0.4, 3)\n",
    "add_node(pgm, 'G', 'G', 1, 2.2)\n",
    "add_node(pgm, 'I', 'I', 1.6, 3)\n",
    "add_node(pgm, 'L', 'L', 1, 1.2)\n",
    "add_node(pgm, 'S', 'S', 2.2, 2.2)\n",
    "add_edges(pgm, [\n",
    "        ('D', 'G'),\n",
    "        ('I', 'G'),\n",
    "        ('I', 'S'),\n",
    "        ('G', 'L')\n",
    "    ])\n",
    "pgm.render()\n",
    "save('bn_example_00')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "image/svg+xml": [
       "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"no\"?>\n",
       "<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\n",
       "  \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n",
       "<!-- Created with matplotlib (http://matplotlib.org/) -->\n",
       "<svg height=\"184pt\" version=\"1.1\" viewBox=\"0 0 241 184\" width=\"241pt\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n",
       " <defs>\n",
       "  <style type=\"text/css\">\n",
       "*{stroke-linecap:butt;stroke-linejoin:round;stroke-miterlimit:100000;}\n",
       "  </style>\n",
       " </defs>\n",
       " <g id=\"figure_1\">\n",
       "  <g id=\"patch_1\">\n",
       "   <path d=\"M 0 184.47874 \n",
       "L 241.171654 184.47874 \n",
       "L 241.171654 0 \n",
       "L 0 0 \n",
       "L 0 184.47874 \n",
       "z\n",
       "\" style=\"fill:none;\"/>\n",
       "  </g>\n",
       "  <g id=\"axes_1\">\n",
       "   <g id=\"patch_2\">\n",
       "    <path clip-path=\"url(#p800664f8ef)\" d=\"M 82.034646 67.294488 \n",
       "L 78.633071 66.302362 \n",
       "L 80.333858 65.026772 \n",
       "L 68.428346 49.152756 \n",
       "L 68.428346 49.152756 \n",
       "L 80.333858 65.026772 \n",
       "L 82.034646 63.751181 \n",
       "L 82.034646 67.294488 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_3\">\n",
       "    <path clip-path=\"url(#p800664f8ef)\" d=\"M 102.444094 67.294488 \n",
       "L 102.444094 63.751181 \n",
       "L 104.144882 65.026772 \n",
       "L 116.050394 49.152756 \n",
       "L 116.050394 49.152756 \n",
       "L 104.144882 65.026772 \n",
       "L 105.845669 66.302362 \n",
       "L 102.444094 67.294488 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_4\">\n",
       "    <path clip-path=\"url(#p800664f8ef)\" d=\"M 150.066142 67.294488 \n",
       "L 146.664567 66.302362 \n",
       "L 148.365354 65.026772 \n",
       "L 136.459843 49.152756 \n",
       "L 136.459843 49.152756 \n",
       "L 148.365354 65.026772 \n",
       "L 150.066142 63.751181 \n",
       "L 150.066142 67.294488 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_5\">\n",
       "    <path clip-path=\"url(#p800664f8ef)\" d=\"M 92.23937 120.585827 \n",
       "L 90.113386 117.751181 \n",
       "L 92.23937 117.751181 \n",
       "L 92.23937 97.908661 \n",
       "L 92.23937 97.908661 \n",
       "L 92.23937 117.751181 \n",
       "L 94.365354 117.751181 \n",
       "L 92.23937 120.585827 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_6\">\n",
       "    <path clip-path=\"url(#p800664f8ef)\" d=\"M 75.231496 35.546457 \n",
       "L 78.066142 33.420472 \n",
       "L 78.066142 35.546457 \n",
       "L 109.247244 35.546457 \n",
       "L 109.247244 35.546457 \n",
       "L 78.066142 35.546457 \n",
       "L 78.066142 37.672441 \n",
       "L 75.231496 35.546457 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_7\">\n",
       "    <path clip-path=\"url(#p800664f8ef)\" d=\"M 58.223622 52.554331 \n",
       "C 62.734163 52.554331 67.060571 50.762274 70.250005 47.57284 \n",
       "C 73.439439 44.383406 75.231496 40.056998 75.231496 35.546457 \n",
       "C 75.231496 31.035916 73.439439 26.709508 70.250005 23.520074 \n",
       "C 67.060571 20.33064 62.734163 18.538583 58.223622 18.538583 \n",
       "C 53.713081 18.538583 49.386673 20.33064 46.197239 23.520074 \n",
       "C 43.007805 26.709508 41.215748 31.035916 41.215748 35.546457 \n",
       "C 41.215748 40.056998 43.007805 44.383406 46.197239 47.57284 \n",
       "C 49.386673 50.762274 53.713081 52.554331 58.223622 52.554331 \n",
       "L 58.223622 52.554331 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_8\">\n",
       "    <path clip-path=\"url(#p800664f8ef)\" d=\"M 126.255118 52.554331 \n",
       "C 130.765659 52.554331 135.092067 50.762274 138.281501 47.57284 \n",
       "C 141.470935 44.383406 143.262992 40.056998 143.262992 35.546457 \n",
       "C 143.262992 31.035916 141.470935 26.709508 138.281501 23.520074 \n",
       "C 135.092067 20.33064 130.765659 18.538583 126.255118 18.538583 \n",
       "C 121.744577 18.538583 117.418169 20.33064 114.228735 23.520074 \n",
       "C 111.039301 26.709508 109.247244 31.035916 109.247244 35.546457 \n",
       "C 109.247244 40.056998 111.039301 44.383406 114.228735 47.57284 \n",
       "C 117.418169 50.762274 121.744577 52.554331 126.255118 52.554331 \n",
       "L 126.255118 52.554331 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_9\">\n",
       "    <path clip-path=\"url(#p800664f8ef)\" d=\"M 92.23937 154.601575 \n",
       "C 96.749911 154.601575 101.076319 152.809518 104.265753 149.620084 \n",
       "C 107.455187 146.43065 109.247244 142.104242 109.247244 137.593701 \n",
       "C 109.247244 133.08316 107.455187 128.756752 104.265753 125.567318 \n",
       "C 101.076319 122.377884 96.749911 120.585827 92.23937 120.585827 \n",
       "C 87.728829 120.585827 83.402421 122.377884 80.212987 125.567318 \n",
       "C 77.023553 128.756752 75.231496 133.08316 75.231496 137.593701 \n",
       "C 75.231496 142.104242 77.023553 146.43065 80.212987 149.620084 \n",
       "C 83.402421 152.809518 87.728829 154.601575 92.23937 154.601575 \n",
       "L 92.23937 154.601575 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_10\">\n",
       "    <path clip-path=\"url(#p800664f8ef)\" d=\"M 160.270866 97.908661 \n",
       "C 164.781407 97.908661 169.107815 96.116605 172.297249 92.92717 \n",
       "C 175.486683 89.737736 177.27874 85.411328 177.27874 80.900787 \n",
       "C 177.27874 76.390246 175.486683 72.063838 172.297249 68.874404 \n",
       "C 169.107815 65.68497 164.781407 63.892913 160.270866 63.892913 \n",
       "C 155.760325 63.892913 151.433917 65.68497 148.244483 68.874404 \n",
       "C 145.055049 72.063838 143.262992 76.390246 143.262992 80.900787 \n",
       "C 143.262992 85.411328 145.055049 89.737736 148.244483 92.92717 \n",
       "C 151.433917 96.116605 155.760325 97.908661 160.270866 97.908661 \n",
       "L 160.270866 97.908661 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_11\">\n",
       "    <path clip-path=\"url(#p800664f8ef)\" d=\"M 92.23937 97.908661 \n",
       "C 96.749911 97.908661 101.076319 96.116605 104.265753 92.92717 \n",
       "C 107.455187 89.737736 109.247244 85.411328 109.247244 80.900787 \n",
       "C 109.247244 76.390246 107.455187 72.063838 104.265753 68.874404 \n",
       "C 101.076319 65.68497 96.749911 63.892913 92.23937 63.892913 \n",
       "C 87.728829 63.892913 83.402421 65.68497 80.212987 68.874404 \n",
       "C 77.023553 72.063838 75.231496 76.390246 75.231496 80.900787 \n",
       "C 75.231496 85.411328 77.023553 89.737736 80.212987 92.92717 \n",
       "C 83.402421 96.116605 87.728829 97.908661 92.23937 97.908661 \n",
       "L 92.23937 97.908661 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"matplotlib.axis_1\"/>\n",
       "   <g id=\"matplotlib.axis_2\"/>\n",
       "   <g id=\"text_1\">\n",
       "    <!-- D -->\n",
       "    <defs>\n",
       "     <path d=\"M 19.671875 64.796875 \n",
       "L 19.671875 8.109375 \n",
       "L 31.59375 8.109375 \n",
       "Q 46.6875 8.109375 53.6875 14.9375 \n",
       "Q 60.6875 21.78125 60.6875 36.53125 \n",
       "Q 60.6875 51.171875 53.6875 57.984375 \n",
       "Q 46.6875 64.796875 31.59375 64.796875 \n",
       "z\n",
       "M 9.8125 72.90625 \n",
       "L 30.078125 72.90625 \n",
       "Q 51.265625 72.90625 61.171875 64.09375 \n",
       "Q 71.09375 55.28125 71.09375 36.53125 \n",
       "Q 71.09375 17.671875 61.125 8.828125 \n",
       "Q 51.171875 0 30.078125 0 \n",
       "L 9.8125 0 \n",
       "z\n",
       "\" id=\"BitstreamVeraSans-Roman-44\"/>\n",
       "    </defs>\n",
       "    <g transform=\"translate(51.2936220472 40.5133316929)scale(0.18 -0.18)\">\n",
       "     <use xlink:href=\"#BitstreamVeraSans-Roman-44\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"text_2\">\n",
       "    <!-- I -->\n",
       "    <defs>\n",
       "     <path d=\"M 9.8125 72.90625 \n",
       "L 19.671875 72.90625 \n",
       "L 19.671875 0 \n",
       "L 9.8125 0 \n",
       "z\n",
       "\" id=\"BitstreamVeraSans-Roman-49\"/>\n",
       "    </defs>\n",
       "    <g transform=\"translate(123.60011811 40.5133316929)scale(0.18 -0.18)\">\n",
       "     <use xlink:href=\"#BitstreamVeraSans-Roman-49\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"text_3\">\n",
       "    <!-- L -->\n",
       "    <defs>\n",
       "     <path d=\"M 9.8125 72.90625 \n",
       "L 19.671875 72.90625 \n",
       "L 19.671875 8.296875 \n",
       "L 55.171875 8.296875 \n",
       "L 55.171875 0 \n",
       "L 9.8125 0 \n",
       "z\n",
       "\" id=\"BitstreamVeraSans-Roman-4c\"/>\n",
       "    </defs>\n",
       "    <g transform=\"translate(87.2246825787 142.560575787)scale(0.18 -0.18)\">\n",
       "     <use xlink:href=\"#BitstreamVeraSans-Roman-4c\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"text_4\">\n",
       "    <!-- S -->\n",
       "    <defs>\n",
       "     <path d=\"M 53.515625 70.515625 \n",
       "L 53.515625 60.890625 \n",
       "Q 47.90625 63.578125 42.921875 64.890625 \n",
       "Q 37.9375 66.21875 33.296875 66.21875 \n",
       "Q 25.25 66.21875 20.875 63.09375 \n",
       "Q 16.5 59.96875 16.5 54.203125 \n",
       "Q 16.5 49.359375 19.40625 46.890625 \n",
       "Q 22.3125 44.4375 30.421875 42.921875 \n",
       "L 36.375 41.703125 \n",
       "Q 47.40625 39.59375 52.65625 34.296875 \n",
       "Q 57.90625 29 57.90625 20.125 \n",
       "Q 57.90625 9.515625 50.796875 4.046875 \n",
       "Q 43.703125 -1.421875 29.984375 -1.421875 \n",
       "Q 24.8125 -1.421875 18.96875 -0.25 \n",
       "Q 13.140625 0.921875 6.890625 3.21875 \n",
       "L 6.890625 13.375 \n",
       "Q 12.890625 10.015625 18.65625 8.296875 \n",
       "Q 24.421875 6.59375 29.984375 6.59375 \n",
       "Q 38.421875 6.59375 43.015625 9.90625 \n",
       "Q 47.609375 13.234375 47.609375 19.390625 \n",
       "Q 47.609375 24.75 44.3125 27.78125 \n",
       "Q 41.015625 30.8125 33.5 32.328125 \n",
       "L 27.484375 33.5 \n",
       "Q 16.453125 35.6875 11.515625 40.375 \n",
       "Q 6.59375 45.0625 6.59375 53.421875 \n",
       "Q 6.59375 63.09375 13.40625 68.65625 \n",
       "Q 20.21875 74.21875 32.171875 74.21875 \n",
       "Q 37.3125 74.21875 42.625 73.28125 \n",
       "Q 47.953125 72.359375 53.515625 70.515625 \n",
       "\" id=\"BitstreamVeraSans-Roman-53\"/>\n",
       "    </defs>\n",
       "    <g transform=\"translate(154.557272392 85.8676624016)scale(0.18 -0.18)\">\n",
       "     <use xlink:href=\"#BitstreamVeraSans-Roman-53\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"text_5\">\n",
       "    <!-- G -->\n",
       "    <defs>\n",
       "     <path d=\"M 59.515625 10.40625 \n",
       "L 59.515625 29.984375 \n",
       "L 43.40625 29.984375 \n",
       "L 43.40625 38.09375 \n",
       "L 69.28125 38.09375 \n",
       "L 69.28125 6.78125 \n",
       "Q 63.578125 2.734375 56.6875 0.65625 \n",
       "Q 49.8125 -1.421875 42 -1.421875 \n",
       "Q 24.90625 -1.421875 15.25 8.5625 \n",
       "Q 5.609375 18.5625 5.609375 36.375 \n",
       "Q 5.609375 54.25 15.25 64.234375 \n",
       "Q 24.90625 74.21875 42 74.21875 \n",
       "Q 49.125 74.21875 55.546875 72.453125 \n",
       "Q 61.96875 70.703125 67.390625 67.28125 \n",
       "L 67.390625 56.78125 \n",
       "Q 61.921875 61.421875 55.765625 63.765625 \n",
       "Q 49.609375 66.109375 42.828125 66.109375 \n",
       "Q 29.4375 66.109375 22.71875 58.640625 \n",
       "Q 16.015625 51.171875 16.015625 36.375 \n",
       "Q 16.015625 21.625 22.71875 14.15625 \n",
       "Q 29.4375 6.6875 42.828125 6.6875 \n",
       "Q 48.046875 6.6875 52.140625 7.59375 \n",
       "Q 56.25 8.5 59.515625 10.40625 \n",
       "\" id=\"BitstreamVeraSans-Roman-47\"/>\n",
       "    </defs>\n",
       "    <g transform=\"translate(85.2657763287 85.8676624016)scale(0.18 -0.18)\">\n",
       "     <use xlink:href=\"#BitstreamVeraSans-Roman-47\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "  </g>\n",
       " </g>\n",
       " <defs>\n",
       "  <clipPath id=\"p800664f8ef\">\n",
       "   <rect height=\"170.078740157\" width=\"226.771653543\" x=\"7.2\" y=\"7.2\"/>\n",
       "  </clipPath>\n",
       " </defs>\n",
       "</svg>\n"
      ],
      "text/plain": [
       "<matplotlib.figure.Figure at 0x7feb96975240>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "pgm = daft.PGM([4, 3], origin=[-0.5, 0.5])\n",
    "add_node(pgm, 'D', 'D', 0.4, 3)\n",
    "add_node(pgm, 'G', 'G', 1, 2.2)\n",
    "add_node(pgm, 'I', 'I', 1.6, 3)\n",
    "add_node(pgm, 'L', 'L', 1, 1.2)\n",
    "add_node(pgm, 'S', 'S', 2.2, 2.2)\n",
    "add_edges(pgm, [\n",
    "        ('D', 'G'),\n",
    "        ('I', 'G'),\n",
    "        ('I', 'S'),\n",
    "        ('G', 'L'),\n",
    "        ('I', 'D')\n",
    "    ])\n",
    "pgm.render()\n",
    "save('bn_example_01')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "image/svg+xml": [
       "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"no\"?>\n",
       "<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\n",
       "  \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n",
       "<!-- Created with matplotlib (http://matplotlib.org/) -->\n",
       "<svg height=\"184pt\" version=\"1.1\" viewBox=\"0 0 241 184\" width=\"241pt\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n",
       " <defs>\n",
       "  <style type=\"text/css\">\n",
       "*{stroke-linecap:butt;stroke-linejoin:round;stroke-miterlimit:100000;}\n",
       "  </style>\n",
       " </defs>\n",
       " <g id=\"figure_1\">\n",
       "  <g id=\"patch_1\">\n",
       "   <path d=\"M 0 184.47874 \n",
       "L 241.171654 184.47874 \n",
       "L 241.171654 0 \n",
       "L 0 0 \n",
       "L 0 184.47874 \n",
       "z\n",
       "\" style=\"fill:none;\"/>\n",
       "  </g>\n",
       "  <g id=\"axes_1\">\n",
       "   <g id=\"patch_2\">\n",
       "    <path clip-path=\"url(#p9b80505de3)\" d=\"M 82.034646 67.294488 \n",
       "L 78.633071 66.302362 \n",
       "L 80.333858 65.026772 \n",
       "L 68.428346 49.152756 \n",
       "L 68.428346 49.152756 \n",
       "L 80.333858 65.026772 \n",
       "L 82.034646 63.751181 \n",
       "L 82.034646 67.294488 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_3\">\n",
       "    <path clip-path=\"url(#p9b80505de3)\" d=\"M 102.444094 67.294488 \n",
       "L 102.444094 63.751181 \n",
       "L 104.144882 65.026772 \n",
       "L 116.050394 49.152756 \n",
       "L 116.050394 49.152756 \n",
       "L 104.144882 65.026772 \n",
       "L 105.845669 66.302362 \n",
       "L 102.444094 67.294488 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_4\">\n",
       "    <path clip-path=\"url(#p9b80505de3)\" d=\"M 150.066142 67.294488 \n",
       "L 146.664567 66.302362 \n",
       "L 148.365354 65.026772 \n",
       "L 136.459843 49.152756 \n",
       "L 136.459843 49.152756 \n",
       "L 148.365354 65.026772 \n",
       "L 150.066142 63.751181 \n",
       "L 150.066142 67.294488 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_5\">\n",
       "    <path clip-path=\"url(#p9b80505de3)\" d=\"M 92.23937 120.585827 \n",
       "L 90.113386 117.751181 \n",
       "L 92.23937 117.751181 \n",
       "L 92.23937 97.908661 \n",
       "L 92.23937 97.908661 \n",
       "L 92.23937 117.751181 \n",
       "L 94.365354 117.751181 \n",
       "L 92.23937 120.585827 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_6\">\n",
       "    <path clip-path=\"url(#p9b80505de3)\" d=\"M 58.223622 52.554331 \n",
       "C 62.734163 52.554331 67.060571 50.762274 70.250005 47.57284 \n",
       "C 73.439439 44.383406 75.231496 40.056998 75.231496 35.546457 \n",
       "C 75.231496 31.035916 73.439439 26.709508 70.250005 23.520074 \n",
       "C 67.060571 20.33064 62.734163 18.538583 58.223622 18.538583 \n",
       "C 53.713081 18.538583 49.386673 20.33064 46.197239 23.520074 \n",
       "C 43.007805 26.709508 41.215748 31.035916 41.215748 35.546457 \n",
       "C 41.215748 40.056998 43.007805 44.383406 46.197239 47.57284 \n",
       "C 49.386673 50.762274 53.713081 52.554331 58.223622 52.554331 \n",
       "L 58.223622 52.554331 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_7\">\n",
       "    <path clip-path=\"url(#p9b80505de3)\" d=\"M 126.255118 52.554331 \n",
       "C 130.765659 52.554331 135.092067 50.762274 138.281501 47.57284 \n",
       "C 141.470935 44.383406 143.262992 40.056998 143.262992 35.546457 \n",
       "C 143.262992 31.035916 141.470935 26.709508 138.281501 23.520074 \n",
       "C 135.092067 20.33064 130.765659 18.538583 126.255118 18.538583 \n",
       "C 121.744577 18.538583 117.418169 20.33064 114.228735 23.520074 \n",
       "C 111.039301 26.709508 109.247244 31.035916 109.247244 35.546457 \n",
       "C 109.247244 40.056998 111.039301 44.383406 114.228735 47.57284 \n",
       "C 117.418169 50.762274 121.744577 52.554331 126.255118 52.554331 \n",
       "L 126.255118 52.554331 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_8\">\n",
       "    <path clip-path=\"url(#p9b80505de3)\" d=\"M 92.23937 154.601575 \n",
       "C 96.749911 154.601575 101.076319 152.809518 104.265753 149.620084 \n",
       "C 107.455187 146.43065 109.247244 142.104242 109.247244 137.593701 \n",
       "C 109.247244 133.08316 107.455187 128.756752 104.265753 125.567318 \n",
       "C 101.076319 122.377884 96.749911 120.585827 92.23937 120.585827 \n",
       "C 87.728829 120.585827 83.402421 122.377884 80.212987 125.567318 \n",
       "C 77.023553 128.756752 75.231496 133.08316 75.231496 137.593701 \n",
       "C 75.231496 142.104242 77.023553 146.43065 80.212987 149.620084 \n",
       "C 83.402421 152.809518 87.728829 154.601575 92.23937 154.601575 \n",
       "L 92.23937 154.601575 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_9\">\n",
       "    <path clip-path=\"url(#p9b80505de3)\" d=\"M 160.270866 97.908661 \n",
       "C 164.781407 97.908661 169.107815 96.116605 172.297249 92.92717 \n",
       "C 175.486683 89.737736 177.27874 85.411328 177.27874 80.900787 \n",
       "C 177.27874 76.390246 175.486683 72.063838 172.297249 68.874404 \n",
       "C 169.107815 65.68497 164.781407 63.892913 160.270866 63.892913 \n",
       "C 155.760325 63.892913 151.433917 65.68497 148.244483 68.874404 \n",
       "C 145.055049 72.063838 143.262992 76.390246 143.262992 80.900787 \n",
       "C 143.262992 85.411328 145.055049 89.737736 148.244483 92.92717 \n",
       "C 151.433917 96.116605 155.760325 97.908661 160.270866 97.908661 \n",
       "L 160.270866 97.908661 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_10\">\n",
       "    <path clip-path=\"url(#p9b80505de3)\" d=\"M 92.23937 97.908661 \n",
       "C 96.749911 97.908661 101.076319 96.116605 104.265753 92.92717 \n",
       "C 107.455187 89.737736 109.247244 85.411328 109.247244 80.900787 \n",
       "C 109.247244 76.390246 107.455187 72.063838 104.265753 68.874404 \n",
       "C 101.076319 65.68497 96.749911 63.892913 92.23937 63.892913 \n",
       "C 87.728829 63.892913 83.402421 65.68497 80.212987 68.874404 \n",
       "C 77.023553 72.063838 75.231496 76.390246 75.231496 80.900787 \n",
       "C 75.231496 85.411328 77.023553 89.737736 80.212987 92.92717 \n",
       "C 83.402421 96.116605 87.728829 97.908661 92.23937 97.908661 \n",
       "L 92.23937 97.908661 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"matplotlib.axis_1\"/>\n",
       "   <g id=\"matplotlib.axis_2\"/>\n",
       "   <g id=\"text_1\">\n",
       "    <!-- $P(D)$ -->\n",
       "    <defs>\n",
       "     <path d=\"M 23.90625 66.203125 \n",
       "L 40.5 66.203125 \n",
       "Q 75.09375 66.203125 75.09375 42.90625 \n",
       "Q 75.09375 35.203125 72 27.640625 \n",
       "Q 68.90625 20.09375 63.25 13.890625 \n",
       "Q 57.59375 7.703125 48.640625 3.84375 \n",
       "Q 39.703125 0 28.90625 0 \n",
       "L 7.40625 0 \n",
       "z\n",
       "M 17.90625 7.40625 \n",
       "L 22.796875 7.40625 \n",
       "Q 32.203125 7.40625 37.5 8.15625 \n",
       "Q 42.796875 8.90625 48.203125 11.40625 \n",
       "Q 56.203125 15.09375 61.046875 23.140625 \n",
       "Q 65.90625 31.203125 65.90625 40.90625 \n",
       "Q 65.90625 58.796875 36.703125 58.796875 \n",
       "L 30.703125 58.796875 \n",
       "z\n",
       "\" id=\"STIXGeneral-Italic-1d60b\"/>\n",
       "     <path d=\"M 2.90625 66 \n",
       "L 4.09375 67.59375 \n",
       "Q 15.5 60.796875 22 49.1875 \n",
       "Q 28.5 37.59375 28.5 24.703125 \n",
       "Q 28.5 -2.59375 3.796875 -17.703125 \n",
       "L 2.90625 -16.09375 \n",
       "Q 13.203125 -7.59375 16.546875 0.84375 \n",
       "Q 19.90625 9.296875 19.90625 24.40625 \n",
       "Q 19.90625 39.59375 16.546875 48.75 \n",
       "Q 13.203125 57.90625 2.90625 66 \n",
       "\" id=\"STIXGeneral-Regular-29\"/>\n",
       "     <path d=\"M 30.40625 -16.09375 \n",
       "L 29.203125 -17.703125 \n",
       "Q 17.59375 -11.09375 11.1875 0.5 \n",
       "Q 4.796875 12.09375 4.796875 25.203125 \n",
       "Q 4.796875 52.90625 29.5 67.59375 \n",
       "L 30.40625 66 \n",
       "Q 20.203125 57.296875 16.796875 48.84375 \n",
       "Q 13.40625 40.40625 13.40625 25.5 \n",
       "Q 13.40625 10.703125 16.90625 1.5 \n",
       "Q 20.40625 -7.703125 30.40625 -16.09375 \n",
       "\" id=\"STIXGeneral-Regular-28\"/>\n",
       "     <path d=\"M 23.90625 66.203125 \n",
       "L 42.296875 66.203125 \n",
       "Q 63.796875 66.203125 63.796875 52.90625 \n",
       "Q 63.796875 42.703125 55.6875 35.59375 \n",
       "Q 47.59375 28.5 35.203125 28.5 \n",
       "L 23.203125 28.5 \n",
       "L 16.09375 0 \n",
       "L 7.40625 0 \n",
       "z\n",
       "M 25 35.90625 \n",
       "L 33.796875 35.90625 \n",
       "Q 44.296875 35.90625 49.5 39.953125 \n",
       "Q 54.703125 44 54.703125 50.796875 \n",
       "Q 54.703125 58.796875 39 58.796875 \n",
       "L 30.703125 58.796875 \n",
       "z\n",
       "\" id=\"STIXGeneral-Italic-1d617\"/>\n",
       "    </defs>\n",
       "    <g transform=\"translate(47.8286220472 38.5817691929)scale(0.11 -0.11)\">\n",
       "     <use transform=\"translate(0.0 0.40625)\" xlink:href=\"#STIXGeneral-Italic-1d617\"/>\n",
       "     <use transform=\"translate(52.49998474121094 0.40625)\" xlink:href=\"#STIXGeneral-Regular-28\"/>\n",
       "     <use transform=\"translate(85.79997253417969 0.40625)\" xlink:href=\"#STIXGeneral-Italic-1d60b\"/>\n",
       "     <use transform=\"translate(154.9999542236328 0.40625)\" xlink:href=\"#STIXGeneral-Regular-29\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"text_2\">\n",
       "    <!-- $P(I)$ -->\n",
       "    <defs>\n",
       "     <path d=\"M 51.203125 66.203125 \n",
       "L 50.203125 58.796875 \n",
       "L 39.09375 58.796875 \n",
       "L 26.296875 7.40625 \n",
       "L 37.40625 7.40625 \n",
       "L 34.703125 0 \n",
       "L 5.90625 0 \n",
       "L 6.296875 7.40625 \n",
       "L 17.40625 7.40625 \n",
       "L 30.203125 58.796875 \n",
       "L 19.09375 58.796875 \n",
       "L 22.40625 66.203125 \n",
       "z\n",
       "\" id=\"STIXGeneral-Italic-1d610\"/>\n",
       "    </defs>\n",
       "    <g transform=\"translate(117.45511811 38.5817691929)scale(0.11 -0.11)\">\n",
       "     <use transform=\"translate(0.0 0.40625)\" xlink:href=\"#STIXGeneral-Italic-1d617\"/>\n",
       "     <use transform=\"translate(52.49998474121094 0.40625)\" xlink:href=\"#STIXGeneral-Regular-28\"/>\n",
       "     <use transform=\"translate(85.79997253417969 0.40625)\" xlink:href=\"#STIXGeneral-Italic-1d610\"/>\n",
       "     <use transform=\"translate(125.89996337890625 0.40625)\" xlink:href=\"#STIXGeneral-Regular-29\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"text_3\">\n",
       "    <!-- $P(L|G)$ -->\n",
       "    <defs>\n",
       "     <path d=\"M 13.296875 -1.40625 \n",
       "L 6.703125 -1.40625 \n",
       "L 6.703125 67.59375 \n",
       "L 13.296875 67.59375 \n",
       "z\n",
       "\" id=\"STIXGeneral-Regular-7c\"/>\n",
       "     <path d=\"M 56.40625 7.40625 \n",
       "L 52.796875 0 \n",
       "L 7.40625 0 \n",
       "L 23.90625 66.203125 \n",
       "L 32.59375 66.203125 \n",
       "L 17.90625 7.40625 \n",
       "z\n",
       "\" id=\"STIXGeneral-Italic-1d613\"/>\n",
       "     <path d=\"M 75.5 56.5 \n",
       "L 73 46.203125 \n",
       "L 71.09375 46.203125 \n",
       "Q 67.90625 60 52.203125 60 \n",
       "Q 42.796875 60 35.046875 54.953125 \n",
       "Q 27.296875 49.90625 23.140625 42.203125 \n",
       "Q 19 34.5 19 26.203125 \n",
       "Q 19 17.5 24.203125 11.84375 \n",
       "Q 29.40625 6.203125 39.40625 6.203125 \n",
       "Q 47.703125 6.203125 52.046875 8 \n",
       "Q 56.40625 9.796875 57 12.296875 \n",
       "L 61 28.09375 \n",
       "L 52.09375 28.09375 \n",
       "L 52.09375 35.703125 \n",
       "L 71.59375 35.703125 \n",
       "L 64.09375 5.90625 \n",
       "Q 59.59375 3.296875 57.1875 2.1875 \n",
       "Q 54.796875 1.09375 49.34375 -0.15625 \n",
       "Q 43.90625 -1.40625 37.09375 -1.40625 \n",
       "Q 24.203125 -1.40625 16.953125 5.34375 \n",
       "Q 9.703125 12.09375 9.703125 23.40625 \n",
       "Q 9.703125 32.09375 13.34375 40.25 \n",
       "Q 17 48.40625 23.046875 54.40625 \n",
       "Q 29.09375 60.40625 37.296875 64 \n",
       "Q 45.5 67.59375 54.09375 67.59375 \n",
       "Q 70.59375 67.59375 75.5 56.5 \n",
       "\" id=\"STIXGeneral-Italic-1d60e\"/>\n",
       "    </defs>\n",
       "    <g transform=\"translate(78.9893700787 140.353075787)scale(0.1 -0.1)\">\n",
       "     <use transform=\"translate(0.0 0.40625)\" xlink:href=\"#STIXGeneral-Italic-1d617\"/>\n",
       "     <use transform=\"translate(52.49998474121094 0.40625)\" xlink:href=\"#STIXGeneral-Regular-28\"/>\n",
       "     <use transform=\"translate(85.79997253417969 0.40625)\" xlink:href=\"#STIXGeneral-Italic-1d613\"/>\n",
       "     <use transform=\"translate(141.69996643066406 0.40625)\" xlink:href=\"#STIXGeneral-Regular-7c\"/>\n",
       "     <use transform=\"translate(161.699951171875 0.40625)\" xlink:href=\"#STIXGeneral-Italic-1d60e\"/>\n",
       "     <use transform=\"translate(231.19993591308594 0.40625)\" xlink:href=\"#STIXGeneral-Regular-29\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"text_4\">\n",
       "    <!-- $P(S|I)$ -->\n",
       "    <defs>\n",
       "     <path d=\"M 59.703125 59.59375 \n",
       "L 56.703125 47.703125 \n",
       "L 54.796875 47.703125 \n",
       "Q 53.90625 53.703125 49.90625 56.84375 \n",
       "Q 45.90625 60 40.09375 60 \n",
       "Q 35 60 30.953125 56.5 \n",
       "Q 26.90625 53 26.90625 48.796875 \n",
       "Q 26.90625 42.90625 38.09375 37.796875 \n",
       "Q 46 34.296875 49.453125 30.59375 \n",
       "Q 52.90625 26.90625 52.90625 21.90625 \n",
       "Q 52.90625 11.5 44.65625 5.046875 \n",
       "Q 36.40625 -1.40625 25.40625 -1.40625 \n",
       "Q 10.90625 -1.40625 6.203125 7 \n",
       "L 8.296875 20.5 \n",
       "L 10.09375 20.5 \n",
       "Q 11.5 13.203125 16.34375 9.703125 \n",
       "Q 21.203125 6.203125 26.90625 6.203125 \n",
       "Q 34.296875 6.203125 38.890625 9.75 \n",
       "Q 43.5 13.296875 43.5 18.59375 \n",
       "Q 43.5 21.90625 41.140625 24.34375 \n",
       "Q 38.796875 26.796875 33.59375 29.09375 \n",
       "Q 25.40625 32.796875 21.65625 36.640625 \n",
       "Q 17.90625 40.5 17.90625 45.59375 \n",
       "Q 17.90625 55 25.34375 61.296875 \n",
       "Q 32.796875 67.59375 42.5 67.59375 \n",
       "Q 54.90625 67.59375 59.703125 59.59375 \n",
       "\" id=\"STIXGeneral-Italic-1d61a\"/>\n",
       "    </defs>\n",
       "    <g transform=\"translate(147.400866142 83.9360999016)scale(0.11 -0.11)\">\n",
       "     <use transform=\"translate(0.0 0.40625)\" xlink:href=\"#STIXGeneral-Italic-1d617\"/>\n",
       "     <use transform=\"translate(52.49998474121094 0.40625)\" xlink:href=\"#STIXGeneral-Regular-28\"/>\n",
       "     <use transform=\"translate(85.79997253417969 0.40625)\" xlink:href=\"#STIXGeneral-Italic-1d61a\"/>\n",
       "     <use transform=\"translate(139.89996337890625 0.40625)\" xlink:href=\"#STIXGeneral-Regular-7c\"/>\n",
       "     <use transform=\"translate(159.8999481201172 0.40625)\" xlink:href=\"#STIXGeneral-Italic-1d610\"/>\n",
       "     <use transform=\"translate(199.99993896484375 0.40625)\" xlink:href=\"#STIXGeneral-Regular-29\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"text_5\">\n",
       "    <!-- $P(G\\,|D,I)$ -->\n",
       "    <defs>\n",
       "     <path d=\"M 8.296875 -14.09375 \n",
       "L 7.296875 -12.203125 \n",
       "Q 15.59375 -6.59375 15.59375 -1.5 \n",
       "Q 15.59375 -0.203125 14.203125 -0.203125 \n",
       "Q 13.796875 -0.203125 12.84375 -0.390625 \n",
       "Q 11.90625 -0.59375 11.296875 -0.59375 \n",
       "Q 5.5 -0.59375 5.5 4.5 \n",
       "Q 5.5 7.09375 7.140625 8.640625 \n",
       "Q 8.796875 10.203125 11.5 10.203125 \n",
       "Q 14.90625 10.203125 17.203125 7.75 \n",
       "Q 19.5 5.296875 19.5 1.5 \n",
       "Q 19.5 -3.09375 16.453125 -7.390625 \n",
       "Q 13.40625 -11.703125 8.296875 -14.09375 \n",
       "\" id=\"STIXGeneral-Regular-2c\"/>\n",
       "    </defs>\n",
       "    <g transform=\"translate(75.5443700787 83.3842249016)scale(0.09 -0.09)\">\n",
       "     <use transform=\"translate(0.0 0.40625)\" xlink:href=\"#STIXGeneral-Italic-1d617\"/>\n",
       "     <use transform=\"translate(52.49998474121094 0.40625)\" xlink:href=\"#STIXGeneral-Regular-28\"/>\n",
       "     <use transform=\"translate(85.79997253417969 0.40625)\" xlink:href=\"#STIXGeneral-Italic-1d60e\"/>\n",
       "     <use transform=\"translate(167.9002077494812 0.40625)\" xlink:href=\"#STIXGeneral-Regular-7c\"/>\n",
       "     <use transform=\"translate(187.90019249069215 0.40625)\" xlink:href=\"#STIXGeneral-Italic-1d60b\"/>\n",
       "     <use transform=\"translate(257.10017418014525 0.40625)\" xlink:href=\"#STIXGeneral-Regular-2c\"/>\n",
       "     <use transform=\"translate(297.2201570903015 0.40625)\" xlink:href=\"#STIXGeneral-Italic-1d610\"/>\n",
       "     <use transform=\"translate(337.32014793502805 0.40625)\" xlink:href=\"#STIXGeneral-Regular-29\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "  </g>\n",
       " </g>\n",
       " <defs>\n",
       "  <clipPath id=\"p9b80505de3\">\n",
       "   <rect height=\"170.078740157\" width=\"226.771653543\" x=\"7.2\" y=\"7.2\"/>\n",
       "  </clipPath>\n",
       " </defs>\n",
       "</svg>\n"
      ],
      "text/plain": [
       "<matplotlib.figure.Figure at 0x7feb96e2b7b8>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "pgm = daft.PGM([4, 3], origin=[-0.5, 0.5])\n",
    "add_node(pgm, 'D', '$P(D)$', 0.4, 3, label_params={'size':11})\n",
    "add_node(pgm, 'G', '$P(G\\,|D,I)$', 1, 2.2, label_params={'size':9})\n",
    "add_node(pgm, 'I', '$P(I)$', 1.6, 3, label_params={'size':11})\n",
    "add_node(pgm, 'L', '$P(L|G)$', 1, 1.2, label_params={'size':10})\n",
    "add_node(pgm, 'S', '$P(S|I)$', 2.2, 2.2, label_params={'size': 11})\n",
    "add_edges(pgm, [\n",
    "        ('D', 'G'),\n",
    "        ('I', 'G'),\n",
    "        ('I', 'S'),\n",
    "        ('G', 'L')\n",
    "    ])\n",
    "pgm.render()\n",
    "save('bn_example_02')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "image/svg+xml": [
       "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"no\"?>\n",
       "<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\n",
       "  \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n",
       "<!-- Created with matplotlib (http://matplotlib.org/) -->\n",
       "<svg height=\"127pt\" version=\"1.1\" viewBox=\"0 0 156 127\" width=\"156pt\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n",
       " <defs>\n",
       "  <style type=\"text/css\">\n",
       "*{stroke-linecap:butt;stroke-linejoin:round;stroke-miterlimit:100000;}\n",
       "  </style>\n",
       " </defs>\n",
       " <g id=\"figure_1\">\n",
       "  <g id=\"patch_1\">\n",
       "   <path d=\"M 0 127.785827 \n",
       "L 156.132283 127.785827 \n",
       "L 156.132283 0 \n",
       "L 0 0 \n",
       "L 0 127.785827 \n",
       "z\n",
       "\" style=\"fill:none;\"/>\n",
       "  </g>\n",
       "  <g id=\"axes_1\">\n",
       "   <g id=\"patch_2\">\n",
       "    <path clip-path=\"url(#pc0f61e58f5)\" d=\"M 82.034646 67.294488 \n",
       "L 78.633071 66.302362 \n",
       "L 80.333858 65.026772 \n",
       "L 68.428346 49.152756 \n",
       "L 68.428346 49.152756 \n",
       "L 80.333858 65.026772 \n",
       "L 82.034646 63.751181 \n",
       "L 82.034646 67.294488 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_3\">\n",
       "    <path clip-path=\"url(#pc0f61e58f5)\" d=\"M 102.444094 67.294488 \n",
       "L 102.444094 63.751181 \n",
       "L 104.144882 65.026772 \n",
       "L 116.050394 49.152756 \n",
       "L 116.050394 49.152756 \n",
       "L 104.144882 65.026772 \n",
       "L 105.845669 66.302362 \n",
       "L 102.444094 67.294488 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_4\">\n",
       "    <path clip-path=\"url(#pc0f61e58f5)\" d=\"M 58.223622 52.554331 \n",
       "C 62.734163 52.554331 67.060571 50.762274 70.250005 47.57284 \n",
       "C 73.439439 44.383406 75.231496 40.056998 75.231496 35.546457 \n",
       "C 75.231496 31.035916 73.439439 26.709508 70.250005 23.520074 \n",
       "C 67.060571 20.33064 62.734163 18.538583 58.223622 18.538583 \n",
       "C 53.713081 18.538583 49.386673 20.33064 46.197239 23.520074 \n",
       "C 43.007805 26.709508 41.215748 31.035916 41.215748 35.546457 \n",
       "C 41.215748 40.056998 43.007805 44.383406 46.197239 47.57284 \n",
       "C 49.386673 50.762274 53.713081 52.554331 58.223622 52.554331 \n",
       "L 58.223622 52.554331 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_5\">\n",
       "    <path clip-path=\"url(#pc0f61e58f5)\" d=\"M 92.23937 97.908661 \n",
       "C 96.749911 97.908661 101.076319 96.116605 104.265753 92.92717 \n",
       "C 107.455187 89.737736 109.247244 85.411328 109.247244 80.900787 \n",
       "C 109.247244 76.390246 107.455187 72.063838 104.265753 68.874404 \n",
       "C 101.076319 65.68497 96.749911 63.892913 92.23937 63.892913 \n",
       "C 87.728829 63.892913 83.402421 65.68497 80.212987 68.874404 \n",
       "C 77.023553 72.063838 75.231496 76.390246 75.231496 80.900787 \n",
       "C 75.231496 85.411328 77.023553 89.737736 80.212987 92.92717 \n",
       "C 83.402421 96.116605 87.728829 97.908661 92.23937 97.908661 \n",
       "L 92.23937 97.908661 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_6\">\n",
       "    <path clip-path=\"url(#pc0f61e58f5)\" d=\"M 126.255118 52.554331 \n",
       "C 130.765659 52.554331 135.092067 50.762274 138.281501 47.57284 \n",
       "C 141.470935 44.383406 143.262992 40.056998 143.262992 35.546457 \n",
       "C 143.262992 31.035916 141.470935 26.709508 138.281501 23.520074 \n",
       "C 135.092067 20.33064 130.765659 18.538583 126.255118 18.538583 \n",
       "C 121.744577 18.538583 117.418169 20.33064 114.228735 23.520074 \n",
       "C 111.039301 26.709508 109.247244 31.035916 109.247244 35.546457 \n",
       "C 109.247244 40.056998 111.039301 44.383406 114.228735 47.57284 \n",
       "C 117.418169 50.762274 121.744577 52.554331 126.255118 52.554331 \n",
       "L 126.255118 52.554331 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"matplotlib.axis_1\"/>\n",
       "   <g id=\"matplotlib.axis_2\"/>\n",
       "   <g id=\"text_1\">\n",
       "    <!-- $X_1$ -->\n",
       "    <defs>\n",
       "     <path d=\"M 80.59375 66.203125 \n",
       "L 48.90625 34.90625 \n",
       "L 66.90625 0 \n",
       "L 56.40625 0 \n",
       "L 41.90625 28.296875 \n",
       "L 13.59375 0 \n",
       "L 3.09375 0 \n",
       "L 38.296875 34.90625 \n",
       "L 22.09375 66.203125 \n",
       "L 32.703125 66.203125 \n",
       "L 45.203125 41.40625 \n",
       "L 69.90625 66.203125 \n",
       "z\n",
       "\" id=\"STIXGeneral-Italic-1d61f\"/>\n",
       "     <path d=\"M 30.203125 0 \n",
       "L 22.296875 0 \n",
       "L 22.296875 57 \n",
       "Q 20.09375 56 15.75 53.75 \n",
       "Q 11.40625 51.5 10.796875 51.203125 \n",
       "L 10.796875 58.5 \n",
       "L 28.796875 67.703125 \n",
       "L 30.203125 67.203125 \n",
       "z\n",
       "\" id=\"STIXGeneral-Regular-1d7e3\"/>\n",
       "    </defs>\n",
       "    <g transform=\"translate(48.5036220472 40.5133316929)scale(0.18 -0.18)\">\n",
       "     <use transform=\"translate(0.0 0.796875)\" xlink:href=\"#STIXGeneral-Italic-1d61f\"/>\n",
       "     <use transform=\"translate(69.99998474121094 -12.792187499999997)scale(0.7)\" xlink:href=\"#STIXGeneral-Regular-1d7e3\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"text_2\">\n",
       "    <!-- Y -->\n",
       "    <defs>\n",
       "     <path d=\"M -0.203125 72.90625 \n",
       "L 10.40625 72.90625 \n",
       "L 30.609375 42.921875 \n",
       "L 50.6875 72.90625 \n",
       "L 61.28125 72.90625 \n",
       "L 35.5 34.71875 \n",
       "L 35.5 0 \n",
       "L 25.59375 0 \n",
       "L 25.59375 34.71875 \n",
       "z\n",
       "\" id=\"BitstreamVeraSans-Roman-59\"/>\n",
       "    </defs>\n",
       "    <g transform=\"translate(86.7423388287 85.8676624016)scale(0.18 -0.18)\">\n",
       "     <use xlink:href=\"#BitstreamVeraSans-Roman-59\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"text_3\">\n",
       "    <!-- $X_2$ -->\n",
       "    <defs>\n",
       "     <path d=\"M 46.90625 7.09375 \n",
       "L 44 0 \n",
       "L 3.5 0 \n",
       "L 3.5 2.09375 \n",
       "L 21 23.5 \n",
       "L 21 23.40625 \n",
       "L 26.59375 30.203125 \n",
       "Q 30.5 34.90625 32.09375 36.953125 \n",
       "Q 33.703125 39 35.203125 41.953125 \n",
       "Q 36.703125 44.90625 36.703125 47.5 \n",
       "Q 36.703125 53.703125 33.34375 57.09375 \n",
       "Q 30 60.5 24.203125 60.5 \n",
       "Q 19.59375 60.5 15.75 56.703125 \n",
       "Q 11.90625 52.90625 10.90625 45.90625 \n",
       "L 3.703125 47.59375 \n",
       "Q 5.296875 56.5 11.1875 62.046875 \n",
       "Q 17.09375 67.59375 24.90625 67.59375 \n",
       "Q 33.59375 67.59375 39.09375 62.1875 \n",
       "Q 44.59375 56.796875 44.59375 49.09375 \n",
       "Q 44.59375 43.5 42.5 39.453125 \n",
       "Q 40.40625 35.40625 33.703125 27 \n",
       "L 17.703125 7.09375 \n",
       "z\n",
       "\" id=\"STIXGeneral-Regular-1d7e4\"/>\n",
       "    </defs>\n",
       "    <g transform=\"translate(116.53511811 40.5133316929)scale(0.18 -0.18)\">\n",
       "     <use transform=\"translate(0.0 0.796875)\" xlink:href=\"#STIXGeneral-Italic-1d61f\"/>\n",
       "     <use transform=\"translate(69.99998474121094 -12.792187499999997)scale(0.7)\" xlink:href=\"#STIXGeneral-Regular-1d7e4\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "  </g>\n",
       " </g>\n",
       " <defs>\n",
       "  <clipPath id=\"pc0f61e58f5\">\n",
       "   <rect height=\"113.385826772\" width=\"141.732283465\" x=\"7.2\" y=\"7.2\"/>\n",
       "  </clipPath>\n",
       " </defs>\n",
       "</svg>\n"
      ],
      "text/plain": [
       "<matplotlib.figure.Figure at 0x7feb96af5080>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "pgm = daft.PGM([2.5, 2], origin=[-0.5, 0.5])\n",
    "add_node(pgm, 'X_1', '$X_1$', 0.4, 2)\n",
    "add_node(pgm, 'Y', 'Y', 1, 1.2)\n",
    "add_node(pgm, 'X_2', '$X_2$', 1.6, 2)\n",
    "add_edges(pgm, [\n",
    "        ('X_1', 'Y'),\n",
    "        ('X_2', 'Y'),\n",
    "    ])\n",
    "pgm.render()\n",
    "save('bn_or_gate')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "image/svg+xml": [
       "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"no\"?>\n",
       "<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\n",
       "  \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n",
       "<!-- Created with matplotlib (http://matplotlib.org/) -->\n",
       "<svg height=\"127pt\" version=\"1.1\" viewBox=\"0 0 156 127\" width=\"156pt\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n",
       " <defs>\n",
       "  <style type=\"text/css\">\n",
       "*{stroke-linecap:butt;stroke-linejoin:round;stroke-miterlimit:100000;}\n",
       "  </style>\n",
       " </defs>\n",
       " <g id=\"figure_1\">\n",
       "  <g id=\"patch_1\">\n",
       "   <path d=\"M 0 127.785827 \n",
       "L 156.132283 127.785827 \n",
       "L 156.132283 0 \n",
       "L 0 0 \n",
       "L 0 127.785827 \n",
       "z\n",
       "\" style=\"fill:none;\"/>\n",
       "  </g>\n",
       "  <g id=\"axes_1\">\n",
       "   <g id=\"patch_2\">\n",
       "    <path clip-path=\"url(#p6359178fd4)\" d=\"M 68.428346 67.294488 \n",
       "L 68.428346 63.751181 \n",
       "L 70.129134 65.026772 \n",
       "L 82.034646 49.152756 \n",
       "L 82.034646 49.152756 \n",
       "L 70.129134 65.026772 \n",
       "L 71.829921 66.302362 \n",
       "L 68.428346 67.294488 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_3\">\n",
       "    <path clip-path=\"url(#p6359178fd4)\" d=\"M 116.050394 67.294488 \n",
       "L 112.648819 66.302362 \n",
       "L 114.349606 65.026772 \n",
       "L 102.444094 49.152756 \n",
       "L 102.444094 49.152756 \n",
       "L 114.349606 65.026772 \n",
       "L 116.050394 63.751181 \n",
       "L 116.050394 67.294488 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_4\">\n",
       "    <path clip-path=\"url(#p6359178fd4)\" d=\"M 58.223622 97.908661 \n",
       "C 62.734163 97.908661 67.060571 96.116605 70.250005 92.92717 \n",
       "C 73.439439 89.737736 75.231496 85.411328 75.231496 80.900787 \n",
       "C 75.231496 76.390246 73.439439 72.063838 70.250005 68.874404 \n",
       "C 67.060571 65.68497 62.734163 63.892913 58.223622 63.892913 \n",
       "C 53.713081 63.892913 49.386673 65.68497 46.197239 68.874404 \n",
       "C 43.007805 72.063838 41.215748 76.390246 41.215748 80.900787 \n",
       "C 41.215748 85.411328 43.007805 89.737736 46.197239 92.92717 \n",
       "C 49.386673 96.116605 53.713081 97.908661 58.223622 97.908661 \n",
       "L 58.223622 97.908661 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_5\">\n",
       "    <path clip-path=\"url(#p6359178fd4)\" d=\"M 92.23937 52.554331 \n",
       "C 96.749911 52.554331 101.076319 50.762274 104.265753 47.57284 \n",
       "C 107.455187 44.383406 109.247244 40.056998 109.247244 35.546457 \n",
       "C 109.247244 31.035916 107.455187 26.709508 104.265753 23.520074 \n",
       "C 101.076319 20.33064 96.749911 18.538583 92.23937 18.538583 \n",
       "C 87.728829 18.538583 83.402421 20.33064 80.212987 23.520074 \n",
       "C 77.023553 26.709508 75.231496 31.035916 75.231496 35.546457 \n",
       "C 75.231496 40.056998 77.023553 44.383406 80.212987 47.57284 \n",
       "C 83.402421 50.762274 87.728829 52.554331 92.23937 52.554331 \n",
       "L 92.23937 52.554331 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_6\">\n",
       "    <path clip-path=\"url(#p6359178fd4)\" d=\"M 126.255118 97.908661 \n",
       "C 130.765659 97.908661 135.092067 96.116605 138.281501 92.92717 \n",
       "C 141.470935 89.737736 143.262992 85.411328 143.262992 80.900787 \n",
       "C 143.262992 76.390246 141.470935 72.063838 138.281501 68.874404 \n",
       "C 135.092067 65.68497 130.765659 63.892913 126.255118 63.892913 \n",
       "C 121.744577 63.892913 117.418169 65.68497 114.228735 68.874404 \n",
       "C 111.039301 72.063838 109.247244 76.390246 109.247244 80.900787 \n",
       "C 109.247244 85.411328 111.039301 89.737736 114.228735 92.92717 \n",
       "C 117.418169 96.116605 121.744577 97.908661 126.255118 97.908661 \n",
       "L 126.255118 97.908661 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"matplotlib.axis_1\"/>\n",
       "   <g id=\"matplotlib.axis_2\"/>\n",
       "   <g id=\"text_1\">\n",
       "    <!-- toss 1 -->\n",
       "    <defs>\n",
       "     <path id=\"BitstreamVeraSans-Roman-20\"/>\n",
       "     <path d=\"M 18.3125 70.21875 \n",
       "L 18.3125 54.6875 \n",
       "L 36.8125 54.6875 \n",
       "L 36.8125 47.703125 \n",
       "L 18.3125 47.703125 \n",
       "L 18.3125 18.015625 \n",
       "Q 18.3125 11.328125 20.140625 9.421875 \n",
       "Q 21.96875 7.515625 27.59375 7.515625 \n",
       "L 36.8125 7.515625 \n",
       "L 36.8125 0 \n",
       "L 27.59375 0 \n",
       "Q 17.1875 0 13.234375 3.875 \n",
       "Q 9.28125 7.765625 9.28125 18.015625 \n",
       "L 9.28125 47.703125 \n",
       "L 2.6875 47.703125 \n",
       "L 2.6875 54.6875 \n",
       "L 9.28125 54.6875 \n",
       "L 9.28125 70.21875 \n",
       "z\n",
       "\" id=\"BitstreamVeraSans-Roman-74\"/>\n",
       "     <path d=\"M 44.28125 53.078125 \n",
       "L 44.28125 44.578125 \n",
       "Q 40.484375 46.53125 36.375 47.5 \n",
       "Q 32.28125 48.484375 27.875 48.484375 \n",
       "Q 21.1875 48.484375 17.84375 46.4375 \n",
       "Q 14.5 44.390625 14.5 40.28125 \n",
       "Q 14.5 37.15625 16.890625 35.375 \n",
       "Q 19.28125 33.59375 26.515625 31.984375 \n",
       "L 29.59375 31.296875 \n",
       "Q 39.15625 29.25 43.1875 25.515625 \n",
       "Q 47.21875 21.78125 47.21875 15.09375 \n",
       "Q 47.21875 7.46875 41.1875 3.015625 \n",
       "Q 35.15625 -1.421875 24.609375 -1.421875 \n",
       "Q 20.21875 -1.421875 15.453125 -0.5625 \n",
       "Q 10.6875 0.296875 5.421875 2 \n",
       "L 5.421875 11.28125 \n",
       "Q 10.40625 8.6875 15.234375 7.390625 \n",
       "Q 20.0625 6.109375 24.8125 6.109375 \n",
       "Q 31.15625 6.109375 34.5625 8.28125 \n",
       "Q 37.984375 10.453125 37.984375 14.40625 \n",
       "Q 37.984375 18.0625 35.515625 20.015625 \n",
       "Q 33.0625 21.96875 24.703125 23.78125 \n",
       "L 21.578125 24.515625 \n",
       "Q 13.234375 26.265625 9.515625 29.90625 \n",
       "Q 5.8125 33.546875 5.8125 39.890625 \n",
       "Q 5.8125 47.609375 11.28125 51.796875 \n",
       "Q 16.75 56 26.8125 56 \n",
       "Q 31.78125 56 36.171875 55.265625 \n",
       "Q 40.578125 54.546875 44.28125 53.078125 \n",
       "\" id=\"BitstreamVeraSans-Roman-73\"/>\n",
       "     <path d=\"M 12.40625 8.296875 \n",
       "L 28.515625 8.296875 \n",
       "L 28.515625 63.921875 \n",
       "L 10.984375 60.40625 \n",
       "L 10.984375 69.390625 \n",
       "L 28.421875 72.90625 \n",
       "L 38.28125 72.90625 \n",
       "L 38.28125 8.296875 \n",
       "L 54.390625 8.296875 \n",
       "L 54.390625 0 \n",
       "L 12.40625 0 \n",
       "z\n",
       "\" id=\"BitstreamVeraSans-Roman-31\"/>\n",
       "     <path d=\"M 30.609375 48.390625 \n",
       "Q 23.390625 48.390625 19.1875 42.75 \n",
       "Q 14.984375 37.109375 14.984375 27.296875 \n",
       "Q 14.984375 17.484375 19.15625 11.84375 \n",
       "Q 23.34375 6.203125 30.609375 6.203125 \n",
       "Q 37.796875 6.203125 41.984375 11.859375 \n",
       "Q 46.1875 17.53125 46.1875 27.296875 \n",
       "Q 46.1875 37.015625 41.984375 42.703125 \n",
       "Q 37.796875 48.390625 30.609375 48.390625 \n",
       "M 30.609375 56 \n",
       "Q 42.328125 56 49.015625 48.375 \n",
       "Q 55.71875 40.765625 55.71875 27.296875 \n",
       "Q 55.71875 13.875 49.015625 6.21875 \n",
       "Q 42.328125 -1.421875 30.609375 -1.421875 \n",
       "Q 18.84375 -1.421875 12.171875 6.21875 \n",
       "Q 5.515625 13.875 5.515625 27.296875 \n",
       "Q 5.515625 40.765625 12.171875 48.375 \n",
       "Q 18.84375 56 30.609375 56 \n",
       "\" id=\"BitstreamVeraSans-Roman-6f\"/>\n",
       "    </defs>\n",
       "    <g transform=\"translate(44.7243251722 83.3842249016)scale(0.09 -0.09)\">\n",
       "     <use xlink:href=\"#BitstreamVeraSans-Roman-74\"/>\n",
       "     <use x=\"39.208984375\" xlink:href=\"#BitstreamVeraSans-Roman-6f\"/>\n",
       "     <use x=\"100.390625\" xlink:href=\"#BitstreamVeraSans-Roman-73\"/>\n",
       "     <use x=\"152.490234375\" xlink:href=\"#BitstreamVeraSans-Roman-73\"/>\n",
       "     <use x=\"204.58984375\" xlink:href=\"#BitstreamVeraSans-Roman-20\"/>\n",
       "     <use x=\"236.376953125\" xlink:href=\"#BitstreamVeraSans-Roman-31\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"text_2\">\n",
       "    <!-- coin -->\n",
       "    <defs>\n",
       "     <path d=\"M 48.78125 52.59375 \n",
       "L 48.78125 44.1875 \n",
       "Q 44.96875 46.296875 41.140625 47.34375 \n",
       "Q 37.3125 48.390625 33.40625 48.390625 \n",
       "Q 24.65625 48.390625 19.8125 42.84375 \n",
       "Q 14.984375 37.3125 14.984375 27.296875 \n",
       "Q 14.984375 17.28125 19.8125 11.734375 \n",
       "Q 24.65625 6.203125 33.40625 6.203125 \n",
       "Q 37.3125 6.203125 41.140625 7.25 \n",
       "Q 44.96875 8.296875 48.78125 10.40625 \n",
       "L 48.78125 2.09375 \n",
       "Q 45.015625 0.34375 40.984375 -0.53125 \n",
       "Q 36.96875 -1.421875 32.421875 -1.421875 \n",
       "Q 20.0625 -1.421875 12.78125 6.34375 \n",
       "Q 5.515625 14.109375 5.515625 27.296875 \n",
       "Q 5.515625 40.671875 12.859375 48.328125 \n",
       "Q 20.21875 56 33.015625 56 \n",
       "Q 37.15625 56 41.109375 55.140625 \n",
       "Q 45.0625 54.296875 48.78125 52.59375 \n",
       "\" id=\"BitstreamVeraSans-Roman-63\"/>\n",
       "     <path d=\"M 9.421875 54.6875 \n",
       "L 18.40625 54.6875 \n",
       "L 18.40625 0 \n",
       "L 9.421875 0 \n",
       "z\n",
       "M 9.421875 75.984375 \n",
       "L 18.40625 75.984375 \n",
       "L 18.40625 64.59375 \n",
       "L 9.421875 64.59375 \n",
       "z\n",
       "\" id=\"BitstreamVeraSans-Roman-69\"/>\n",
       "     <path d=\"M 54.890625 33.015625 \n",
       "L 54.890625 0 \n",
       "L 45.90625 0 \n",
       "L 45.90625 32.71875 \n",
       "Q 45.90625 40.484375 42.875 44.328125 \n",
       "Q 39.84375 48.1875 33.796875 48.1875 \n",
       "Q 26.515625 48.1875 22.3125 43.546875 \n",
       "Q 18.109375 38.921875 18.109375 30.90625 \n",
       "L 18.109375 0 \n",
       "L 9.078125 0 \n",
       "L 9.078125 54.6875 \n",
       "L 18.109375 54.6875 \n",
       "L 18.109375 46.1875 \n",
       "Q 21.34375 51.125 25.703125 53.5625 \n",
       "Q 30.078125 56 35.796875 56 \n",
       "Q 45.21875 56 50.046875 50.171875 \n",
       "Q 54.890625 44.34375 54.890625 33.015625 \n",
       "\" id=\"BitstreamVeraSans-Roman-6e\"/>\n",
       "    </defs>\n",
       "    <g transform=\"translate(82.9096044537 38.0298941929)scale(0.09 -0.09)\">\n",
       "     <use xlink:href=\"#BitstreamVeraSans-Roman-63\"/>\n",
       "     <use x=\"54.98046875\" xlink:href=\"#BitstreamVeraSans-Roman-6f\"/>\n",
       "     <use x=\"116.162109375\" xlink:href=\"#BitstreamVeraSans-Roman-69\"/>\n",
       "     <use x=\"143.9453125\" xlink:href=\"#BitstreamVeraSans-Roman-6e\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"text_3\">\n",
       "    <!-- toss 2 -->\n",
       "    <defs>\n",
       "     <path d=\"M 19.1875 8.296875 \n",
       "L 53.609375 8.296875 \n",
       "L 53.609375 0 \n",
       "L 7.328125 0 \n",
       "L 7.328125 8.296875 \n",
       "Q 12.9375 14.109375 22.625 23.890625 \n",
       "Q 32.328125 33.6875 34.8125 36.53125 \n",
       "Q 39.546875 41.84375 41.421875 45.53125 \n",
       "Q 43.3125 49.21875 43.3125 52.78125 \n",
       "Q 43.3125 58.59375 39.234375 62.25 \n",
       "Q 35.15625 65.921875 28.609375 65.921875 \n",
       "Q 23.96875 65.921875 18.8125 64.3125 \n",
       "Q 13.671875 62.703125 7.8125 59.421875 \n",
       "L 7.8125 69.390625 \n",
       "Q 13.765625 71.78125 18.9375 73 \n",
       "Q 24.125 74.21875 28.421875 74.21875 \n",
       "Q 39.75 74.21875 46.484375 68.546875 \n",
       "Q 53.21875 62.890625 53.21875 53.421875 \n",
       "Q 53.21875 48.921875 51.53125 44.890625 \n",
       "Q 49.859375 40.875 45.40625 35.40625 \n",
       "Q 44.1875 33.984375 37.640625 27.21875 \n",
       "Q 31.109375 20.453125 19.1875 8.296875 \n",
       "\" id=\"BitstreamVeraSans-Roman-32\"/>\n",
       "    </defs>\n",
       "    <g transform=\"translate(112.755821235 83.3842249016)scale(0.09 -0.09)\">\n",
       "     <use xlink:href=\"#BitstreamVeraSans-Roman-74\"/>\n",
       "     <use x=\"39.208984375\" xlink:href=\"#BitstreamVeraSans-Roman-6f\"/>\n",
       "     <use x=\"100.390625\" xlink:href=\"#BitstreamVeraSans-Roman-73\"/>\n",
       "     <use x=\"152.490234375\" xlink:href=\"#BitstreamVeraSans-Roman-73\"/>\n",
       "     <use x=\"204.58984375\" xlink:href=\"#BitstreamVeraSans-Roman-20\"/>\n",
       "     <use x=\"236.376953125\" xlink:href=\"#BitstreamVeraSans-Roman-32\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "  </g>\n",
       " </g>\n",
       " <defs>\n",
       "  <clipPath id=\"p6359178fd4\">\n",
       "   <rect height=\"113.385826772\" width=\"141.732283465\" x=\"7.2\" y=\"7.2\"/>\n",
       "  </clipPath>\n",
       " </defs>\n",
       "</svg>\n"
      ],
      "text/plain": [
       "<matplotlib.figure.Figure at 0x7feb96af5240>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "pgm = daft.PGM([2.5, 2], origin=[-0.5, 0.5])\n",
    "add_node(pgm, 'X_1', 'toss 1', 0.4, 1.2, label_params={'size':9})\n",
    "add_node(pgm, 'Y', 'coin', 1, 2, label_params={'size':9})\n",
    "add_node(pgm, 'X_2', 'toss 2', 1.6, 1.2, label_params={'size':9})\n",
    "add_edges(pgm, [\n",
    "        ('Y', 'X_1'),\n",
    "        ('Y', 'X_2'),\n",
    "    ])\n",
    "pgm.render()\n",
    "save('bn_coin_toss')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "image/svg+xml": [
       "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"no\"?>\n",
       "<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\n",
       "  \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n",
       "<!-- Created with matplotlib (http://matplotlib.org/) -->\n",
       "<svg height=\"127pt\" version=\"1.1\" viewBox=\"0 0 156 127\" width=\"156pt\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n",
       " <defs>\n",
       "  <style type=\"text/css\">\n",
       "*{stroke-linecap:butt;stroke-linejoin:round;stroke-miterlimit:100000;}\n",
       "  </style>\n",
       " </defs>\n",
       " <g id=\"figure_1\">\n",
       "  <g id=\"patch_1\">\n",
       "   <path d=\"M 0 127.785827 \n",
       "L 156.132283 127.785827 \n",
       "L 156.132283 0 \n",
       "L 0 0 \n",
       "L 0 127.785827 \n",
       "z\n",
       "\" style=\"fill:none;\"/>\n",
       "  </g>\n",
       "  <g id=\"axes_1\">\n",
       "   <g id=\"patch_2\">\n",
       "    <path clip-path=\"url(#p35f14eee4c)\" d=\"M 82.034646 67.294488 \n",
       "L 78.633071 66.302362 \n",
       "L 80.333858 65.026772 \n",
       "L 68.428346 49.152756 \n",
       "L 68.428346 49.152756 \n",
       "L 80.333858 65.026772 \n",
       "L 82.034646 63.751181 \n",
       "L 82.034646 67.294488 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_3\">\n",
       "    <path clip-path=\"url(#p35f14eee4c)\" d=\"M 102.444094 67.294488 \n",
       "L 102.444094 63.751181 \n",
       "L 104.144882 65.026772 \n",
       "L 116.050394 49.152756 \n",
       "L 116.050394 49.152756 \n",
       "L 104.144882 65.026772 \n",
       "L 105.845669 66.302362 \n",
       "L 102.444094 67.294488 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_4\">\n",
       "    <path clip-path=\"url(#p35f14eee4c)\" d=\"M 58.223622 52.554331 \n",
       "C 62.734163 52.554331 67.060571 50.762274 70.250005 47.57284 \n",
       "C 73.439439 44.383406 75.231496 40.056998 75.231496 35.546457 \n",
       "C 75.231496 31.035916 73.439439 26.709508 70.250005 23.520074 \n",
       "C 67.060571 20.33064 62.734163 18.538583 58.223622 18.538583 \n",
       "C 53.713081 18.538583 49.386673 20.33064 46.197239 23.520074 \n",
       "C 43.007805 26.709508 41.215748 31.035916 41.215748 35.546457 \n",
       "C 41.215748 40.056998 43.007805 44.383406 46.197239 47.57284 \n",
       "C 49.386673 50.762274 53.713081 52.554331 58.223622 52.554331 \n",
       "L 58.223622 52.554331 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_5\">\n",
       "    <path clip-path=\"url(#p35f14eee4c)\" d=\"M 126.255118 52.554331 \n",
       "C 130.765659 52.554331 135.092067 50.762274 138.281501 47.57284 \n",
       "C 141.470935 44.383406 143.262992 40.056998 143.262992 35.546457 \n",
       "C 143.262992 31.035916 141.470935 26.709508 138.281501 23.520074 \n",
       "C 135.092067 20.33064 130.765659 18.538583 126.255118 18.538583 \n",
       "C 121.744577 18.538583 117.418169 20.33064 114.228735 23.520074 \n",
       "C 111.039301 26.709508 109.247244 31.035916 109.247244 35.546457 \n",
       "C 109.247244 40.056998 111.039301 44.383406 114.228735 47.57284 \n",
       "C 117.418169 50.762274 121.744577 52.554331 126.255118 52.554331 \n",
       "L 126.255118 52.554331 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_6\">\n",
       "    <path clip-path=\"url(#p35f14eee4c)\" d=\"M 92.23937 97.908661 \n",
       "C 96.749911 97.908661 101.076319 96.116605 104.265753 92.92717 \n",
       "C 107.455187 89.737736 109.247244 85.411328 109.247244 80.900787 \n",
       "C 109.247244 76.390246 107.455187 72.063838 104.265753 68.874404 \n",
       "C 101.076319 65.68497 96.749911 63.892913 92.23937 63.892913 \n",
       "C 87.728829 63.892913 83.402421 65.68497 80.212987 68.874404 \n",
       "C 77.023553 72.063838 75.231496 76.390246 75.231496 80.900787 \n",
       "C 75.231496 85.411328 77.023553 89.737736 80.212987 92.92717 \n",
       "C 83.402421 96.116605 87.728829 97.908661 92.23937 97.908661 \n",
       "L 92.23937 97.908661 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"matplotlib.axis_1\"/>\n",
       "   <g id=\"matplotlib.axis_2\"/>\n",
       "   <g id=\"text_1\">\n",
       "    <!-- I -->\n",
       "    <defs>\n",
       "     <path d=\"M 9.8125 72.90625 \n",
       "L 19.671875 72.90625 \n",
       "L 19.671875 0 \n",
       "L 9.8125 0 \n",
       "z\n",
       "\" id=\"BitstreamVeraSans-Roman-49\"/>\n",
       "    </defs>\n",
       "    <g transform=\"translate(55.5686220472 40.5133316929)scale(0.18 -0.18)\">\n",
       "     <use xlink:href=\"#BitstreamVeraSans-Roman-49\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"text_2\">\n",
       "    <!-- D -->\n",
       "    <defs>\n",
       "     <path d=\"M 19.671875 64.796875 \n",
       "L 19.671875 8.109375 \n",
       "L 31.59375 8.109375 \n",
       "Q 46.6875 8.109375 53.6875 14.9375 \n",
       "Q 60.6875 21.78125 60.6875 36.53125 \n",
       "Q 60.6875 51.171875 53.6875 57.984375 \n",
       "Q 46.6875 64.796875 31.59375 64.796875 \n",
       "z\n",
       "M 9.8125 72.90625 \n",
       "L 30.078125 72.90625 \n",
       "Q 51.265625 72.90625 61.171875 64.09375 \n",
       "Q 71.09375 55.28125 71.09375 36.53125 \n",
       "Q 71.09375 17.671875 61.125 8.828125 \n",
       "Q 51.171875 0 30.078125 0 \n",
       "L 9.8125 0 \n",
       "z\n",
       "\" id=\"BitstreamVeraSans-Roman-44\"/>\n",
       "    </defs>\n",
       "    <g transform=\"translate(119.32511811 40.5133316929)scale(0.18 -0.18)\">\n",
       "     <use xlink:href=\"#BitstreamVeraSans-Roman-44\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"text_3\">\n",
       "    <!-- G -->\n",
       "    <defs>\n",
       "     <path d=\"M 59.515625 10.40625 \n",
       "L 59.515625 29.984375 \n",
       "L 43.40625 29.984375 \n",
       "L 43.40625 38.09375 \n",
       "L 69.28125 38.09375 \n",
       "L 69.28125 6.78125 \n",
       "Q 63.578125 2.734375 56.6875 0.65625 \n",
       "Q 49.8125 -1.421875 42 -1.421875 \n",
       "Q 24.90625 -1.421875 15.25 8.5625 \n",
       "Q 5.609375 18.5625 5.609375 36.375 \n",
       "Q 5.609375 54.25 15.25 64.234375 \n",
       "Q 24.90625 74.21875 42 74.21875 \n",
       "Q 49.125 74.21875 55.546875 72.453125 \n",
       "Q 61.96875 70.703125 67.390625 67.28125 \n",
       "L 67.390625 56.78125 \n",
       "Q 61.921875 61.421875 55.765625 63.765625 \n",
       "Q 49.609375 66.109375 42.828125 66.109375 \n",
       "Q 29.4375 66.109375 22.71875 58.640625 \n",
       "Q 16.015625 51.171875 16.015625 36.375 \n",
       "Q 16.015625 21.625 22.71875 14.15625 \n",
       "Q 29.4375 6.6875 42.828125 6.6875 \n",
       "Q 48.046875 6.6875 52.140625 7.59375 \n",
       "Q 56.25 8.5 59.515625 10.40625 \n",
       "\" id=\"BitstreamVeraSans-Roman-47\"/>\n",
       "    </defs>\n",
       "    <g transform=\"translate(85.2657763287 85.8676624016)scale(0.18 -0.18)\">\n",
       "     <use xlink:href=\"#BitstreamVeraSans-Roman-47\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "  </g>\n",
       " </g>\n",
       " <defs>\n",
       "  <clipPath id=\"p35f14eee4c\">\n",
       "   <rect height=\"113.385826772\" width=\"141.732283465\" x=\"7.2\" y=\"7.2\"/>\n",
       "  </clipPath>\n",
       " </defs>\n",
       "</svg>\n"
      ],
      "text/plain": [
       "<matplotlib.figure.Figure at 0x7feb96b43438>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "pgm = daft.PGM([2.5, 2], origin=[-0.5, 0.5])\n",
    "add_node(pgm, 'I', 'I', 0.4, 2)\n",
    "add_node(pgm, 'G', 'G', 1, 1.2)\n",
    "add_node(pgm, 'D', 'D', 1.6, 2)\n",
    "add_edges(pgm, [\n",
    "        ('I', 'G'),\n",
    "        ('D', 'G'),\n",
    "    ])\n",
    "pgm.render()\n",
    "save('bn_student_or')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "image/svg+xml": [
       "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"no\"?>\n",
       "<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\n",
       "  \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n",
       "<!-- Created with matplotlib (http://matplotlib.org/) -->\n",
       "<svg height=\"127pt\" version=\"1.1\" viewBox=\"0 0 156 127\" width=\"156pt\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n",
       " <defs>\n",
       "  <style type=\"text/css\">\n",
       "*{stroke-linecap:butt;stroke-linejoin:round;stroke-miterlimit:100000;}\n",
       "  </style>\n",
       " </defs>\n",
       " <g id=\"figure_1\">\n",
       "  <g id=\"patch_1\">\n",
       "   <path d=\"M 0 127.785827 \n",
       "L 156.132283 127.785827 \n",
       "L 156.132283 0 \n",
       "L 0 0 \n",
       "L 0 127.785827 \n",
       "z\n",
       "\" style=\"fill:none;\"/>\n",
       "  </g>\n",
       "  <g id=\"axes_1\">\n",
       "   <g id=\"patch_2\">\n",
       "    <path clip-path=\"url(#pa0003fbffe)\" d=\"M 47.57284 68.874404 \n",
       "L 48.073939 65.366709 \n",
       "L 49.577237 66.870007 \n",
       "L 68.874404 47.57284 \n",
       "L 68.874404 47.57284 \n",
       "L 49.577237 66.870007 \n",
       "L 51.080535 68.373305 \n",
       "L 47.57284 68.874404 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_3\">\n",
       "    <path clip-path=\"url(#pa0003fbffe)\" d=\"M 114.228735 68.874404 \n",
       "L 110.72104 68.373305 \n",
       "L 112.224338 66.870007 \n",
       "L 92.92717 47.57284 \n",
       "L 92.92717 47.57284 \n",
       "L 112.224338 66.870007 \n",
       "L 113.727636 65.366709 \n",
       "L 114.228735 68.874404 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_4\">\n",
       "    <path clip-path=\"url(#pa0003fbffe)\" d=\"M 80.900787 63.892913 \n",
       "L 78.774803 61.058268 \n",
       "L 80.900787 61.058268 \n",
       "L 80.900787 52.554331 \n",
       "L 80.900787 52.554331 \n",
       "L 80.900787 61.058268 \n",
       "L 83.026772 61.058268 \n",
       "L 80.900787 63.892913 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_5\">\n",
       "    <path clip-path=\"url(#pa0003fbffe)\" d=\"M 35.546457 97.908661 \n",
       "C 40.056998 97.908661 44.383406 96.116605 47.57284 92.92717 \n",
       "C 50.762274 89.737736 52.554331 85.411328 52.554331 80.900787 \n",
       "C 52.554331 76.390246 50.762274 72.063838 47.57284 68.874404 \n",
       "C 44.383406 65.68497 40.056998 63.892913 35.546457 63.892913 \n",
       "C 31.035916 63.892913 26.709508 65.68497 23.520074 68.874404 \n",
       "C 20.33064 72.063838 18.538583 76.390246 18.538583 80.900787 \n",
       "C 18.538583 85.411328 20.33064 89.737736 23.520074 92.92717 \n",
       "C 26.709508 96.116605 31.035916 97.908661 35.546457 97.908661 \n",
       "L 35.546457 97.908661 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_6\">\n",
       "    <path clip-path=\"url(#pa0003fbffe)\" d=\"M 126.255118 97.908661 \n",
       "C 130.765659 97.908661 135.092067 96.116605 138.281501 92.92717 \n",
       "C 141.470935 89.737736 143.262992 85.411328 143.262992 80.900787 \n",
       "C 143.262992 76.390246 141.470935 72.063838 138.281501 68.874404 \n",
       "C 135.092067 65.68497 130.765659 63.892913 126.255118 63.892913 \n",
       "C 121.744577 63.892913 117.418169 65.68497 114.228735 68.874404 \n",
       "C 111.039301 72.063838 109.247244 76.390246 109.247244 80.900787 \n",
       "C 109.247244 85.411328 111.039301 89.737736 114.228735 92.92717 \n",
       "C 117.418169 96.116605 121.744577 97.908661 126.255118 97.908661 \n",
       "L 126.255118 97.908661 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_7\">\n",
       "    <path clip-path=\"url(#pa0003fbffe)\" d=\"M 80.900787 52.554331 \n",
       "C 85.411328 52.554331 89.737736 50.762274 92.92717 47.57284 \n",
       "C 96.116605 44.383406 97.908661 40.056998 97.908661 35.546457 \n",
       "C 97.908661 31.035916 96.116605 26.709508 92.92717 23.520074 \n",
       "C 89.737736 20.33064 85.411328 18.538583 80.900787 18.538583 \n",
       "C 76.390246 18.538583 72.063838 20.33064 68.874404 23.520074 \n",
       "C 65.68497 26.709508 63.892913 31.035916 63.892913 35.546457 \n",
       "C 63.892913 40.056998 65.68497 44.383406 68.874404 47.57284 \n",
       "C 72.063838 50.762274 76.390246 52.554331 80.900787 52.554331 \n",
       "L 80.900787 52.554331 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_8\">\n",
       "    <path clip-path=\"url(#pa0003fbffe)\" d=\"M 80.900787 97.908661 \n",
       "C 85.411328 97.908661 89.737736 96.116605 92.92717 92.92717 \n",
       "C 96.116605 89.737736 97.908661 85.411328 97.908661 80.900787 \n",
       "C 97.908661 76.390246 96.116605 72.063838 92.92717 68.874404 \n",
       "C 89.737736 65.68497 85.411328 63.892913 80.900787 63.892913 \n",
       "C 76.390246 63.892913 72.063838 65.68497 68.874404 68.874404 \n",
       "C 65.68497 72.063838 63.892913 76.390246 63.892913 80.900787 \n",
       "C 63.892913 85.411328 65.68497 89.737736 68.874404 92.92717 \n",
       "C 72.063838 96.116605 76.390246 97.908661 80.900787 97.908661 \n",
       "L 80.900787 97.908661 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"matplotlib.axis_1\"/>\n",
       "   <g id=\"matplotlib.axis_2\"/>\n",
       "   <g id=\"text_1\">\n",
       "    <!-- $X_1$ -->\n",
       "    <defs>\n",
       "     <path d=\"M 80.59375 66.203125 \n",
       "L 48.90625 34.90625 \n",
       "L 66.90625 0 \n",
       "L 56.40625 0 \n",
       "L 41.90625 28.296875 \n",
       "L 13.59375 0 \n",
       "L 3.09375 0 \n",
       "L 38.296875 34.90625 \n",
       "L 22.09375 66.203125 \n",
       "L 32.703125 66.203125 \n",
       "L 45.203125 41.40625 \n",
       "L 69.90625 66.203125 \n",
       "z\n",
       "\" id=\"STIXGeneral-Italic-1d61f\"/>\n",
       "     <path d=\"M 30.203125 0 \n",
       "L 22.296875 0 \n",
       "L 22.296875 57 \n",
       "Q 20.09375 56 15.75 53.75 \n",
       "Q 11.40625 51.5 10.796875 51.203125 \n",
       "L 10.796875 58.5 \n",
       "L 28.796875 67.703125 \n",
       "L 30.203125 67.203125 \n",
       "z\n",
       "\" id=\"STIXGeneral-Regular-1d7e3\"/>\n",
       "    </defs>\n",
       "    <g transform=\"translate(25.8264566929 85.8676624016)scale(0.18 -0.18)\">\n",
       "     <use transform=\"translate(0.0 0.796875)\" xlink:href=\"#STIXGeneral-Italic-1d61f\"/>\n",
       "     <use transform=\"translate(69.99998474121094 -12.792187499999997)scale(0.7)\" xlink:href=\"#STIXGeneral-Regular-1d7e3\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"text_2\">\n",
       "    <!-- $X_n$ -->\n",
       "    <defs>\n",
       "     <path d=\"M 25.09375 45.90625 \n",
       "L 23.90625 40.203125 \n",
       "Q 28.40625 43.796875 32.203125 45.046875 \n",
       "Q 36 46.296875 40.5 46.296875 \n",
       "Q 45.203125 46.296875 48.09375 43.75 \n",
       "Q 51 41.203125 51 37.203125 \n",
       "Q 51 34.796875 50.40625 32.09375 \n",
       "L 42.40625 0 \n",
       "L 34.5 0 \n",
       "L 42 30.40625 \n",
       "Q 42.5 32.59375 42.5 33.90625 \n",
       "Q 42.5 39.203125 36 39.203125 \n",
       "Q 33.09375 39.203125 28.640625 36.703125 \n",
       "Q 24.203125 34.203125 21.703125 30.203125 \n",
       "L 14.203125 0 \n",
       "L 6.296875 0 \n",
       "L 17.203125 44 \n",
       "L 24.296875 46.40625 \n",
       "z\n",
       "\" id=\"STIXGeneral-Italic-1d62f\"/>\n",
       "    </defs>\n",
       "    <g transform=\"translate(116.62511811 85.8676624016)scale(0.18 -0.18)\">\n",
       "     <use transform=\"translate(0.0 0.796875)\" xlink:href=\"#STIXGeneral-Italic-1d61f\"/>\n",
       "     <use transform=\"translate(69.99998474121094 -12.792187499999997)scale(0.7)\" xlink:href=\"#STIXGeneral-Italic-1d62f\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"text_3\">\n",
       "    <!-- class -->\n",
       "    <defs>\n",
       "     <path d=\"M 48.78125 52.59375 \n",
       "L 48.78125 44.1875 \n",
       "Q 44.96875 46.296875 41.140625 47.34375 \n",
       "Q 37.3125 48.390625 33.40625 48.390625 \n",
       "Q 24.65625 48.390625 19.8125 42.84375 \n",
       "Q 14.984375 37.3125 14.984375 27.296875 \n",
       "Q 14.984375 17.28125 19.8125 11.734375 \n",
       "Q 24.65625 6.203125 33.40625 6.203125 \n",
       "Q 37.3125 6.203125 41.140625 7.25 \n",
       "Q 44.96875 8.296875 48.78125 10.40625 \n",
       "L 48.78125 2.09375 \n",
       "Q 45.015625 0.34375 40.984375 -0.53125 \n",
       "Q 36.96875 -1.421875 32.421875 -1.421875 \n",
       "Q 20.0625 -1.421875 12.78125 6.34375 \n",
       "Q 5.515625 14.109375 5.515625 27.296875 \n",
       "Q 5.515625 40.671875 12.859375 48.328125 \n",
       "Q 20.21875 56 33.015625 56 \n",
       "Q 37.15625 56 41.109375 55.140625 \n",
       "Q 45.0625 54.296875 48.78125 52.59375 \n",
       "\" id=\"BitstreamVeraSans-Roman-63\"/>\n",
       "     <path d=\"M 44.28125 53.078125 \n",
       "L 44.28125 44.578125 \n",
       "Q 40.484375 46.53125 36.375 47.5 \n",
       "Q 32.28125 48.484375 27.875 48.484375 \n",
       "Q 21.1875 48.484375 17.84375 46.4375 \n",
       "Q 14.5 44.390625 14.5 40.28125 \n",
       "Q 14.5 37.15625 16.890625 35.375 \n",
       "Q 19.28125 33.59375 26.515625 31.984375 \n",
       "L 29.59375 31.296875 \n",
       "Q 39.15625 29.25 43.1875 25.515625 \n",
       "Q 47.21875 21.78125 47.21875 15.09375 \n",
       "Q 47.21875 7.46875 41.1875 3.015625 \n",
       "Q 35.15625 -1.421875 24.609375 -1.421875 \n",
       "Q 20.21875 -1.421875 15.453125 -0.5625 \n",
       "Q 10.6875 0.296875 5.421875 2 \n",
       "L 5.421875 11.28125 \n",
       "Q 10.40625 8.6875 15.234375 7.390625 \n",
       "Q 20.0625 6.109375 24.8125 6.109375 \n",
       "Q 31.15625 6.109375 34.5625 8.28125 \n",
       "Q 37.984375 10.453125 37.984375 14.40625 \n",
       "Q 37.984375 18.0625 35.515625 20.015625 \n",
       "Q 33.0625 21.96875 24.703125 23.78125 \n",
       "L 21.578125 24.515625 \n",
       "Q 13.234375 26.265625 9.515625 29.90625 \n",
       "Q 5.8125 33.546875 5.8125 39.890625 \n",
       "Q 5.8125 47.609375 11.28125 51.796875 \n",
       "Q 16.75 56 26.8125 56 \n",
       "Q 31.78125 56 36.171875 55.265625 \n",
       "Q 40.578125 54.546875 44.28125 53.078125 \n",
       "\" id=\"BitstreamVeraSans-Roman-73\"/>\n",
       "     <path d=\"M 34.28125 27.484375 \n",
       "Q 23.390625 27.484375 19.1875 25 \n",
       "Q 14.984375 22.515625 14.984375 16.5 \n",
       "Q 14.984375 11.71875 18.140625 8.90625 \n",
       "Q 21.296875 6.109375 26.703125 6.109375 \n",
       "Q 34.1875 6.109375 38.703125 11.40625 \n",
       "Q 43.21875 16.703125 43.21875 25.484375 \n",
       "L 43.21875 27.484375 \n",
       "z\n",
       "M 52.203125 31.203125 \n",
       "L 52.203125 0 \n",
       "L 43.21875 0 \n",
       "L 43.21875 8.296875 \n",
       "Q 40.140625 3.328125 35.546875 0.953125 \n",
       "Q 30.953125 -1.421875 24.3125 -1.421875 \n",
       "Q 15.921875 -1.421875 10.953125 3.296875 \n",
       "Q 6 8.015625 6 15.921875 \n",
       "Q 6 25.140625 12.171875 29.828125 \n",
       "Q 18.359375 34.515625 30.609375 34.515625 \n",
       "L 43.21875 34.515625 \n",
       "L 43.21875 35.40625 \n",
       "Q 43.21875 41.609375 39.140625 45 \n",
       "Q 35.0625 48.390625 27.6875 48.390625 \n",
       "Q 23 48.390625 18.546875 47.265625 \n",
       "Q 14.109375 46.140625 10.015625 43.890625 \n",
       "L 10.015625 52.203125 \n",
       "Q 14.9375 54.109375 19.578125 55.046875 \n",
       "Q 24.21875 56 28.609375 56 \n",
       "Q 40.484375 56 46.34375 49.84375 \n",
       "Q 52.203125 43.703125 52.203125 31.203125 \n",
       "\" id=\"BitstreamVeraSans-Roman-61\"/>\n",
       "     <path d=\"M 9.421875 75.984375 \n",
       "L 18.40625 75.984375 \n",
       "L 18.40625 0 \n",
       "L 9.421875 0 \n",
       "z\n",
       "\" id=\"BitstreamVeraSans-Roman-6c\"/>\n",
       "    </defs>\n",
       "    <g transform=\"translate(69.7302405266 38.0298941929)scale(0.09 -0.09)\">\n",
       "     <use xlink:href=\"#BitstreamVeraSans-Roman-63\"/>\n",
       "     <use x=\"54.98046875\" xlink:href=\"#BitstreamVeraSans-Roman-6c\"/>\n",
       "     <use x=\"82.763671875\" xlink:href=\"#BitstreamVeraSans-Roman-61\"/>\n",
       "     <use x=\"144.04296875\" xlink:href=\"#BitstreamVeraSans-Roman-73\"/>\n",
       "     <use x=\"196.142578125\" xlink:href=\"#BitstreamVeraSans-Roman-73\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"text_4\">\n",
       "    <!-- $\\dots$ -->\n",
       "    <defs>\n",
       "     <path d=\"M 88.796875 4.296875 \n",
       "Q 88.796875 2.09375 87.140625 0.5 \n",
       "Q 85.5 -1.09375 83.203125 -1.09375 \n",
       "Q 80.90625 -1.09375 79.296875 0.5 \n",
       "Q 77.703125 2.09375 77.703125 4.390625 \n",
       "Q 77.703125 6.703125 79.34375 8.34375 \n",
       "Q 81 10 83.296875 10 \n",
       "Q 85.5 10 87.140625 8.296875 \n",
       "Q 88.796875 6.59375 88.796875 4.296875 \n",
       "M 55.5 4.296875 \n",
       "Q 55.5 2.09375 53.84375 0.5 \n",
       "Q 52.203125 -1.09375 49.890625 -1.09375 \n",
       "Q 47.59375 -1.09375 46 0.5 \n",
       "Q 44.40625 2.09375 44.40625 4.390625 \n",
       "Q 44.40625 6.703125 46.046875 8.34375 \n",
       "Q 47.703125 10 50 10 \n",
       "Q 52.203125 10 53.84375 8.296875 \n",
       "Q 55.5 6.59375 55.5 4.296875 \n",
       "M 22.203125 4.296875 \n",
       "Q 22.203125 2.09375 20.546875 0.5 \n",
       "Q 18.90625 -1.09375 16.59375 -1.09375 \n",
       "Q 14.296875 -1.09375 12.6875 0.5 \n",
       "Q 11.09375 2.09375 11.09375 4.390625 \n",
       "Q 11.09375 6.703125 12.75 8.34375 \n",
       "Q 14.40625 10 16.703125 10 \n",
       "Q 18.90625 10 20.546875 8.296875 \n",
       "Q 22.203125 6.59375 22.203125 4.296875 \n",
       "\" id=\"STIXGeneral-Regular-2026\"/>\n",
       "    </defs>\n",
       "    <g transform=\"translate(71.9007874016 85.8676624016)scale(0.18 -0.18)\">\n",
       "     <use xlink:href=\"#STIXGeneral-Regular-2026\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "  </g>\n",
       " </g>\n",
       " <defs>\n",
       "  <clipPath id=\"pa0003fbffe\">\n",
       "   <rect height=\"113.385826772\" width=\"141.732283465\" x=\"7.2\" y=\"7.2\"/>\n",
       "  </clipPath>\n",
       " </defs>\n",
       "</svg>\n"
      ],
      "text/plain": [
       "<matplotlib.figure.Figure at 0x7feb96b430f0>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "pgm = daft.PGM([2.5, 2], origin=[-0.5, 0.5])\n",
    "add_node(pgm, 'X_1', '$X_1$', 0, 1.2)\n",
    "add_node(pgm, 'c', 'class', 0.8, 2, label_params={'size':9})\n",
    "add_node(pgm, 'X', '$\\dots$', 0.8, 1.2)\n",
    "add_node(pgm, 'X_n', '$X_n$', 1.6, 1.2)\n",
    "add_edges(pgm, [\n",
    "        ('c', 'X_1'),\n",
    "        ('c', 'X_n'),\n",
    "        ('c', 'X')\n",
    "    ])\n",
    "pgm.render()\n",
    "save('bn_naive_bayes')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "image/svg+xml": [
       "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"no\"?>\n",
       "<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\n",
       "  \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n",
       "<!-- Created with matplotlib (http://matplotlib.org/) -->\n",
       "<svg height=\"241pt\" version=\"1.1\" viewBox=\"0 0 195 241\" width=\"195pt\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n",
       " <defs>\n",
       "  <style type=\"text/css\">\n",
       "*{stroke-linecap:butt;stroke-linejoin:round;stroke-miterlimit:100000;}\n",
       "  </style>\n",
       " </defs>\n",
       " <g id=\"figure_1\">\n",
       "  <g id=\"patch_1\">\n",
       "   <path d=\"M 0 241.171654 \n",
       "L 195.817323 241.171654 \n",
       "L 195.817323 -0 \n",
       "L 0 -0 \n",
       "L 0 241.171654 \n",
       "z\n",
       "\" style=\"fill:none;\"/>\n",
       "  </g>\n",
       "  <g id=\"axes_1\">\n",
       "   <g id=\"patch_2\">\n",
       "    <path clip-path=\"url(#p1199b870b0)\" d=\"M 86.570079 35.546457 \n",
       "L 83.735433 37.672441 \n",
       "L 83.735433 35.546457 \n",
       "L 52.554331 35.546457 \n",
       "L 52.554331 35.546457 \n",
       "L 83.735433 35.546457 \n",
       "L 83.735433 33.420472 \n",
       "L 86.570079 35.546457 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_3\">\n",
       "    <path clip-path=\"url(#p1199b870b0)\" d=\"M 90.512142 81.351194 \n",
       "L 86.973485 81.169725 \n",
       "L 88.334507 79.536499 \n",
       "L 48.612267 46.434632 \n",
       "L 48.612267 46.434632 \n",
       "L 88.334507 79.536499 \n",
       "L 89.695529 77.903272 \n",
       "L 90.512142 81.351194 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_4\">\n",
       "    <path clip-path=\"url(#p1199b870b0)\" d=\"M 97.261387 189.833782 \n",
       "L 94.234699 187.991451 \n",
       "L 96.208626 187.20188 \n",
       "L 41.863023 51.337871 \n",
       "L 41.863023 51.337871 \n",
       "L 96.208626 187.20188 \n",
       "L 98.182553 186.412309 \n",
       "L 97.261387 189.833782 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_5\">\n",
       "    <path clip-path=\"url(#p1199b870b0)\" d=\"M 86.570079 92.23937 \n",
       "L 83.735433 94.365354 \n",
       "L 83.735433 92.23937 \n",
       "L 52.554331 92.23937 \n",
       "L 52.554331 92.23937 \n",
       "L 83.735433 92.23937 \n",
       "L 83.735433 90.113386 \n",
       "L 86.570079 92.23937 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_6\">\n",
       "    <path clip-path=\"url(#p1199b870b0)\" d=\"M 90.512142 138.044108 \n",
       "L 86.973485 137.862638 \n",
       "L 88.334507 136.229412 \n",
       "L 48.612267 103.127546 \n",
       "L 48.612267 103.127546 \n",
       "L 88.334507 136.229412 \n",
       "L 89.695529 134.596186 \n",
       "L 90.512142 138.044108 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_7\">\n",
       "    <path clip-path=\"url(#p1199b870b0)\" d=\"M 86.570079 148.932283 \n",
       "L 83.735433 151.058268 \n",
       "L 83.735433 148.932283 \n",
       "L 52.554331 148.932283 \n",
       "L 52.554331 148.932283 \n",
       "L 83.735433 148.932283 \n",
       "L 83.735433 146.806299 \n",
       "L 86.570079 148.932283 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_8\">\n",
       "    <path clip-path=\"url(#p1199b870b0)\" d=\"M 86.570079 205.625197 \n",
       "L 83.735433 207.751181 \n",
       "L 83.735433 205.625197 \n",
       "L 52.554331 205.625197 \n",
       "L 52.554331 205.625197 \n",
       "L 83.735433 205.625197 \n",
       "L 83.735433 203.499213 \n",
       "L 86.570079 205.625197 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_9\">\n",
       "    <path clip-path=\"url(#p1199b870b0)\" d=\"M 145.058561 169.672588 \n",
       "L 141.572408 170.306434 \n",
       "L 142.523177 168.404896 \n",
       "L 118.790258 156.538436 \n",
       "L 118.790258 156.538436 \n",
       "L 142.523177 168.404896 \n",
       "L 143.473946 166.503357 \n",
       "L 145.058561 169.672588 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_10\">\n",
       "    <path clip-path=\"url(#p1199b870b0)\" d=\"M 145.058561 184.884893 \n",
       "L 143.473946 188.054123 \n",
       "L 142.523177 186.152585 \n",
       "L 118.790258 198.019044 \n",
       "L 118.790258 198.019044 \n",
       "L 142.523177 186.152585 \n",
       "L 141.572408 184.251047 \n",
       "L 145.058561 184.884893 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_11\">\n",
       "    <path clip-path=\"url(#p1199b870b0)\" d=\"M 103.577953 52.554331 \n",
       "C 108.088494 52.554331 112.414902 50.762274 115.604336 47.57284 \n",
       "C 118.79377 44.383406 120.585827 40.056998 120.585827 35.546457 \n",
       "C 120.585827 31.035916 118.79377 26.709508 115.604336 23.520074 \n",
       "C 112.414902 20.33064 108.088494 18.538583 103.577953 18.538583 \n",
       "C 99.067412 18.538583 94.741004 20.33064 91.55157 23.520074 \n",
       "C 88.362136 26.709508 86.570079 31.035916 86.570079 35.546457 \n",
       "C 86.570079 40.056998 88.362136 44.383406 91.55157 47.57284 \n",
       "C 94.741004 50.762274 99.067412 52.554331 103.577953 52.554331 \n",
       "L 103.577953 52.554331 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_12\">\n",
       "    <path clip-path=\"url(#p1199b870b0)\" d=\"M 103.577953 165.940157 \n",
       "C 108.088494 165.940157 112.414902 164.148101 115.604336 160.958667 \n",
       "C 118.79377 157.769232 120.585827 153.442824 120.585827 148.932283 \n",
       "C 120.585827 144.421743 118.79377 140.095334 115.604336 136.9059 \n",
       "C 112.414902 133.716466 108.088494 131.924409 103.577953 131.924409 \n",
       "C 99.067412 131.924409 94.741004 133.716466 91.55157 136.9059 \n",
       "C 88.362136 140.095334 86.570079 144.421743 86.570079 148.932283 \n",
       "C 86.570079 153.442824 88.362136 157.769232 91.55157 160.958667 \n",
       "C 94.741004 164.148101 99.067412 165.940157 103.577953 165.940157 \n",
       "L 103.577953 165.940157 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_13\">\n",
       "    <path clip-path=\"url(#p1199b870b0)\" d=\"M 103.577953 222.633071 \n",
       "C 108.088494 222.633071 112.414902 220.841014 115.604336 217.65158 \n",
       "C 118.79377 214.462146 120.585827 210.135738 120.585827 205.625197 \n",
       "C 120.585827 201.114656 118.79377 196.788248 115.604336 193.598814 \n",
       "C 112.414902 190.40938 108.088494 188.617323 103.577953 188.617323 \n",
       "C 99.067412 188.617323 94.741004 190.40938 91.55157 193.598814 \n",
       "C 88.362136 196.788248 86.570079 201.114656 86.570079 205.625197 \n",
       "C 86.570079 210.135738 88.362136 214.462146 91.55157 217.65158 \n",
       "C 94.741004 220.841014 99.067412 222.633071 103.577953 222.633071 \n",
       "L 103.577953 222.633071 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_14\">\n",
       "    <path clip-path=\"url(#p1199b870b0)\" d=\"M 35.546457 109.247244 \n",
       "C 40.056998 109.247244 44.383406 107.455187 47.57284 104.265753 \n",
       "C 50.762274 101.076319 52.554331 96.749911 52.554331 92.23937 \n",
       "C 52.554331 87.728829 50.762274 83.402421 47.57284 80.212987 \n",
       "C 44.383406 77.023553 40.056998 75.231496 35.546457 75.231496 \n",
       "C 31.035916 75.231496 26.709508 77.023553 23.520074 80.212987 \n",
       "C 20.33064 83.402421 18.538583 87.728829 18.538583 92.23937 \n",
       "C 18.538583 96.749911 20.33064 101.076319 23.520074 104.265753 \n",
       "C 26.709508 107.455187 31.035916 109.247244 35.546457 109.247244 \n",
       "L 35.546457 109.247244 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_15\">\n",
       "    <path clip-path=\"url(#p1199b870b0)\" d=\"M 35.546457 222.633071 \n",
       "C 40.056998 222.633071 44.383406 220.841014 47.57284 217.65158 \n",
       "C 50.762274 214.462146 52.554331 210.135738 52.554331 205.625197 \n",
       "C 52.554331 201.114656 50.762274 196.788248 47.57284 193.598814 \n",
       "C 44.383406 190.40938 40.056998 188.617323 35.546457 188.617323 \n",
       "C 31.035916 188.617323 26.709508 190.40938 23.520074 193.598814 \n",
       "C 20.33064 196.788248 18.538583 201.114656 18.538583 205.625197 \n",
       "C 18.538583 210.135738 20.33064 214.462146 23.520074 217.65158 \n",
       "C 26.709508 220.841014 31.035916 222.633071 35.546457 222.633071 \n",
       "L 35.546457 222.633071 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_16\">\n",
       "    <path clip-path=\"url(#p1199b870b0)\" d=\"M 35.546457 165.940157 \n",
       "C 40.056998 165.940157 44.383406 164.148101 47.57284 160.958667 \n",
       "C 50.762274 157.769232 52.554331 153.442824 52.554331 148.932283 \n",
       "C 52.554331 144.421743 50.762274 140.095334 47.57284 136.9059 \n",
       "C 44.383406 133.716466 40.056998 131.924409 35.546457 131.924409 \n",
       "C 31.035916 131.924409 26.709508 133.716466 23.520074 136.9059 \n",
       "C 20.33064 140.095334 18.538583 144.421743 18.538583 148.932283 \n",
       "C 18.538583 153.442824 20.33064 157.769232 23.520074 160.958667 \n",
       "C 26.709508 164.148101 31.035916 165.940157 35.546457 165.940157 \n",
       "L 35.546457 165.940157 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_17\">\n",
       "    <path clip-path=\"url(#p1199b870b0)\" d=\"M 103.577953 109.247244 \n",
       "C 108.088494 109.247244 112.414902 107.455187 115.604336 104.265753 \n",
       "C 118.79377 101.076319 120.585827 96.749911 120.585827 92.23937 \n",
       "C 120.585827 87.728829 118.79377 83.402421 115.604336 80.212987 \n",
       "C 112.414902 77.023553 108.088494 75.231496 103.577953 75.231496 \n",
       "C 99.067412 75.231496 94.741004 77.023553 91.55157 80.212987 \n",
       "C 88.362136 83.402421 86.570079 87.728829 86.570079 92.23937 \n",
       "C 86.570079 96.749911 88.362136 101.076319 91.55157 104.265753 \n",
       "C 94.741004 107.455187 99.067412 109.247244 103.577953 109.247244 \n",
       "L 103.577953 109.247244 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_18\">\n",
       "    <path clip-path=\"url(#p1199b870b0)\" d=\"M 35.546457 52.554331 \n",
       "C 40.056998 52.554331 44.383406 50.762274 47.57284 47.57284 \n",
       "C 50.762274 44.383406 52.554331 40.056998 52.554331 35.546457 \n",
       "C 52.554331 31.035916 50.762274 26.709508 47.57284 23.520074 \n",
       "C 44.383406 20.33064 40.056998 18.538583 35.546457 18.538583 \n",
       "C 31.035916 18.538583 26.709508 20.33064 23.520074 23.520074 \n",
       "C 20.33064 26.709508 18.538583 31.035916 18.538583 35.546457 \n",
       "C 18.538583 40.056998 20.33064 44.383406 23.520074 47.57284 \n",
       "C 26.709508 50.762274 31.035916 52.554331 35.546457 52.554331 \n",
       "L 35.546457 52.554331 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_19\">\n",
       "    <path clip-path=\"url(#p1199b870b0)\" d=\"M 160.270866 194.286614 \n",
       "C 164.781407 194.286614 169.107815 192.494557 172.297249 189.305123 \n",
       "C 175.486683 186.115689 177.27874 181.789281 177.27874 177.27874 \n",
       "C 177.27874 172.768199 175.486683 168.441791 172.297249 165.252357 \n",
       "C 169.107815 162.062923 164.781407 160.270866 160.270866 160.270866 \n",
       "C 155.760325 160.270866 151.433917 162.062923 148.244483 165.252357 \n",
       "C 145.055049 168.441791 143.262992 172.768199 143.262992 177.27874 \n",
       "C 143.262992 181.789281 145.055049 186.115689 148.244483 189.305123 \n",
       "C 151.433917 192.494557 155.760325 194.286614 160.270866 194.286614 \n",
       "L 160.270866 194.286614 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"matplotlib.axis_1\"/>\n",
       "   <g id=\"matplotlib.axis_2\"/>\n",
       "   <g id=\"text_1\">\n",
       "    <!-- W' -->\n",
       "    <defs>\n",
       "     <path d=\"M 17.921875 72.90625 \n",
       "L 17.921875 45.796875 \n",
       "L 9.625 45.796875 \n",
       "L 9.625 72.90625 \n",
       "z\n",
       "\" id=\"BitstreamVeraSans-Roman-27\"/>\n",
       "     <path d=\"M 3.328125 72.90625 \n",
       "L 13.28125 72.90625 \n",
       "L 28.609375 11.28125 \n",
       "L 43.890625 72.90625 \n",
       "L 54.984375 72.90625 \n",
       "L 70.3125 11.28125 \n",
       "L 85.59375 72.90625 \n",
       "L 95.609375 72.90625 \n",
       "L 77.296875 0 \n",
       "L 64.890625 0 \n",
       "L 49.515625 63.28125 \n",
       "L 33.984375 0 \n",
       "L 21.578125 0 \n",
       "z\n",
       "\" id=\"BitstreamVeraSans-Roman-57\"/>\n",
       "    </defs>\n",
       "    <g transform=\"translate(92.2056090059 40.5133316929)scale(0.18 -0.18)\">\n",
       "     <use xlink:href=\"#BitstreamVeraSans-Roman-57\"/>\n",
       "     <use x=\"98.876953125\" xlink:href=\"#BitstreamVeraSans-Roman-27\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"text_2\">\n",
       "    <!-- L' -->\n",
       "    <defs>\n",
       "     <path d=\"M 9.8125 72.90625 \n",
       "L 19.671875 72.90625 \n",
       "L 19.671875 8.296875 \n",
       "L 55.171875 8.296875 \n",
       "L 55.171875 0 \n",
       "L 9.8125 0 \n",
       "z\n",
       "\" id=\"BitstreamVeraSans-Roman-4c\"/>\n",
       "    </defs>\n",
       "    <g transform=\"translate(96.0896715059 153.899158465)scale(0.18 -0.18)\">\n",
       "     <use xlink:href=\"#BitstreamVeraSans-Roman-4c\"/>\n",
       "     <use x=\"55.712890625\" xlink:href=\"#BitstreamVeraSans-Roman-27\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"text_3\">\n",
       "    <!-- F' -->\n",
       "    <defs>\n",
       "     <path d=\"M 9.8125 72.90625 \n",
       "L 51.703125 72.90625 \n",
       "L 51.703125 64.59375 \n",
       "L 19.671875 64.59375 \n",
       "L 19.671875 43.109375 \n",
       "L 48.578125 43.109375 \n",
       "L 48.578125 34.8125 \n",
       "L 19.671875 34.8125 \n",
       "L 19.671875 0 \n",
       "L 9.8125 0 \n",
       "z\n",
       "\" id=\"BitstreamVeraSans-Roman-46\"/>\n",
       "    </defs>\n",
       "    <g transform=\"translate(95.9279527559 210.59207185)scale(0.18 -0.18)\">\n",
       "     <use xlink:href=\"#BitstreamVeraSans-Roman-46\"/>\n",
       "     <use x=\"57.51953125\" xlink:href=\"#BitstreamVeraSans-Roman-27\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"text_4\">\n",
       "    <!-- V -->\n",
       "    <defs>\n",
       "     <path d=\"M 28.609375 0 \n",
       "L 0.78125 72.90625 \n",
       "L 11.078125 72.90625 \n",
       "L 34.1875 11.53125 \n",
       "L 57.328125 72.90625 \n",
       "L 67.578125 72.90625 \n",
       "L 39.796875 0 \n",
       "z\n",
       "\" id=\"BitstreamVeraSans-Roman-56\"/>\n",
       "    </defs>\n",
       "    <g transform=\"translate(29.3898941929 97.2062450787)scale(0.18 -0.18)\">\n",
       "     <use xlink:href=\"#BitstreamVeraSans-Roman-56\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"text_5\">\n",
       "    <!-- F -->\n",
       "    <g transform=\"translate(30.3700504429 210.59207185)scale(0.18 -0.18)\">\n",
       "     <use xlink:href=\"#BitstreamVeraSans-Roman-46\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"text_6\">\n",
       "    <!-- L -->\n",
       "    <g transform=\"translate(30.5317691929 153.899158465)scale(0.18 -0.18)\">\n",
       "     <use xlink:href=\"#BitstreamVeraSans-Roman-4c\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"text_7\">\n",
       "    <!-- V' -->\n",
       "    <g transform=\"translate(94.9477965059 97.2062450787)scale(0.18 -0.18)\">\n",
       "     <use xlink:href=\"#BitstreamVeraSans-Roman-56\"/>\n",
       "     <use x=\"68.408203125\" xlink:href=\"#BitstreamVeraSans-Roman-27\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"text_8\">\n",
       "    <!-- W -->\n",
       "    <g transform=\"translate(26.6477066929 40.5133316929)scale(0.18 -0.18)\">\n",
       "     <use xlink:href=\"#BitstreamVeraSans-Roman-57\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"text_9\">\n",
       "    <!-- O' -->\n",
       "    <defs>\n",
       "     <path d=\"M 39.40625 66.21875 \n",
       "Q 28.65625 66.21875 22.328125 58.203125 \n",
       "Q 16.015625 50.203125 16.015625 36.375 \n",
       "Q 16.015625 22.609375 22.328125 14.59375 \n",
       "Q 28.65625 6.59375 39.40625 6.59375 \n",
       "Q 50.140625 6.59375 56.421875 14.59375 \n",
       "Q 62.703125 22.609375 62.703125 36.375 \n",
       "Q 62.703125 50.203125 56.421875 58.203125 \n",
       "Q 50.140625 66.21875 39.40625 66.21875 \n",
       "M 39.40625 74.21875 \n",
       "Q 54.734375 74.21875 63.90625 63.9375 \n",
       "Q 73.09375 53.65625 73.09375 36.375 \n",
       "Q 73.09375 19.140625 63.90625 8.859375 \n",
       "Q 54.734375 -1.421875 39.40625 -1.421875 \n",
       "Q 24.03125 -1.421875 14.8125 8.828125 \n",
       "Q 5.609375 19.09375 5.609375 36.375 \n",
       "Q 5.609375 53.65625 14.8125 63.9375 \n",
       "Q 24.03125 74.21875 39.40625 74.21875 \n",
       "\" id=\"BitstreamVeraSans-Roman-4f\"/>\n",
       "    </defs>\n",
       "    <g transform=\"translate(150.712584892 182.245615157)scale(0.18 -0.18)\">\n",
       "     <use xlink:href=\"#BitstreamVeraSans-Roman-4f\"/>\n",
       "     <use x=\"78.7109375\" xlink:href=\"#BitstreamVeraSans-Roman-27\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "  </g>\n",
       " </g>\n",
       " <defs>\n",
       "  <clipPath id=\"p1199b870b0\">\n",
       "   <rect height=\"226.771653543\" width=\"181.417322835\" x=\"7.2\" y=\"7.2\"/>\n",
       "  </clipPath>\n",
       " </defs>\n",
       "</svg>\n"
      ],
      "text/plain": [
       "<matplotlib.figure.Figure at 0x7feb96c02550>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "pgm = daft.PGM([3.2, 4], origin=[-0.5, 0.5])\n",
    "add_node(pgm, 'W', 'W', 0, 4)\n",
    "add_node(pgm, 'W_', 'W\\'', 1.2, 4)\n",
    "add_node(pgm, 'V', 'V', 0, 3)\n",
    "add_node(pgm, 'V_', 'V\\'', 1.2, 3)\n",
    "add_node(pgm, 'L', 'L', 0, 2)\n",
    "add_node(pgm, 'L_', 'L\\'', 1.2, 2)\n",
    "add_node(pgm, 'F', 'F', 0, 1)\n",
    "add_node(pgm, 'F_', 'F\\'', 1.2, 1)\n",
    "add_node(pgm, 'O_', 'O\\'', 2.2, 1.5)\n",
    "add_edges(pgm, [\n",
    "        ('W', 'W_'),\n",
    "        ('W', 'V_'),\n",
    "        ('W', 'F_'),\n",
    "        ('V', 'V_'),\n",
    "        ('V', 'L_'),\n",
    "        ('L', 'L_'),\n",
    "        ('F', 'F_'),\n",
    "        ('L_', 'O_'),\n",
    "        ('F_', 'O_')\n",
    "    ])\n",
    "pgm.render()\n",
    "save('bn_temporal_ex_00')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "image/svg+xml": [
       "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"no\"?>\n",
       "<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\n",
       "  \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n",
       "<!-- Created with matplotlib (http://matplotlib.org/) -->\n",
       "<svg height=\"241pt\" version=\"1.1\" viewBox=\"0 0 139 241\" width=\"139pt\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n",
       " <defs>\n",
       "  <style type=\"text/css\">\n",
       "*{stroke-linecap:butt;stroke-linejoin:round;stroke-miterlimit:100000;}\n",
       "  </style>\n",
       " </defs>\n",
       " <g id=\"figure_1\">\n",
       "  <g id=\"patch_1\">\n",
       "   <path d=\"M 0 241.171654 \n",
       "L 139.124409 241.171654 \n",
       "L 139.124409 -0 \n",
       "L 0 -0 \n",
       "L 0 241.171654 \n",
       "z\n",
       "\" style=\"fill:none;\"/>\n",
       "  </g>\n",
       "  <g id=\"axes_1\">\n",
       "   <g id=\"patch_2\">\n",
       "    <path clip-path=\"url(#pddc098e815)\" d=\"M 35.546457 109.247244 \n",
       "L 37.672441 112.08189 \n",
       "L 35.546457 112.08189 \n",
       "L 35.546457 131.924409 \n",
       "L 35.546457 131.924409 \n",
       "L 35.546457 112.08189 \n",
       "L 33.420472 112.08189 \n",
       "L 35.546457 109.247244 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_3\">\n",
       "    <path clip-path=\"url(#pddc098e815)\" d=\"M 87.878377 170.73725 \n",
       "L 84.444094 171.609449 \n",
       "L 85.261781 169.647002 \n",
       "L 51.246033 155.473773 \n",
       "L 51.246033 155.473773 \n",
       "L 85.261781 169.647002 \n",
       "L 86.079467 167.684555 \n",
       "L 87.878377 170.73725 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_4\">\n",
       "    <path clip-path=\"url(#pddc098e815)\" d=\"M 87.878377 183.82023 \n",
       "L 86.079467 186.872925 \n",
       "L 85.261781 184.910478 \n",
       "L 51.246033 199.083707 \n",
       "L 51.246033 199.083707 \n",
       "L 85.261781 184.910478 \n",
       "L 84.444094 182.948031 \n",
       "L 87.878377 183.82023 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_5\">\n",
       "    <path clip-path=\"url(#pddc098e815)\" d=\"M 35.546457 109.247244 \n",
       "C 40.056998 109.247244 44.383406 107.455187 47.57284 104.265753 \n",
       "C 50.762274 101.076319 52.554331 96.749911 52.554331 92.23937 \n",
       "C 52.554331 87.728829 50.762274 83.402421 47.57284 80.212987 \n",
       "C 44.383406 77.023553 40.056998 75.231496 35.546457 75.231496 \n",
       "C 31.035916 75.231496 26.709508 77.023553 23.520074 80.212987 \n",
       "C 20.33064 83.402421 18.538583 87.728829 18.538583 92.23937 \n",
       "C 18.538583 96.749911 20.33064 101.076319 23.520074 104.265753 \n",
       "C 26.709508 107.455187 31.035916 109.247244 35.546457 109.247244 \n",
       "L 35.546457 109.247244 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_6\">\n",
       "    <path clip-path=\"url(#pddc098e815)\" d=\"M 103.577953 194.286614 \n",
       "C 108.088494 194.286614 112.414902 192.494557 115.604336 189.305123 \n",
       "C 118.79377 186.115689 120.585827 181.789281 120.585827 177.27874 \n",
       "C 120.585827 172.768199 118.79377 168.441791 115.604336 165.252357 \n",
       "C 112.414902 162.062923 108.088494 160.270866 103.577953 160.270866 \n",
       "C 99.067412 160.270866 94.741004 162.062923 91.55157 165.252357 \n",
       "C 88.362136 168.441791 86.570079 172.768199 86.570079 177.27874 \n",
       "C 86.570079 181.789281 88.362136 186.115689 91.55157 189.305123 \n",
       "C 94.741004 192.494557 99.067412 194.286614 103.577953 194.286614 \n",
       "L 103.577953 194.286614 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_7\">\n",
       "    <path clip-path=\"url(#pddc098e815)\" d=\"M 35.546457 165.940157 \n",
       "C 40.056998 165.940157 44.383406 164.148101 47.57284 160.958667 \n",
       "C 50.762274 157.769232 52.554331 153.442824 52.554331 148.932283 \n",
       "C 52.554331 144.421743 50.762274 140.095334 47.57284 136.9059 \n",
       "C 44.383406 133.716466 40.056998 131.924409 35.546457 131.924409 \n",
       "C 31.035916 131.924409 26.709508 133.716466 23.520074 136.9059 \n",
       "C 20.33064 140.095334 18.538583 144.421743 18.538583 148.932283 \n",
       "C 18.538583 153.442824 20.33064 157.769232 23.520074 160.958667 \n",
       "C 26.709508 164.148101 31.035916 165.940157 35.546457 165.940157 \n",
       "L 35.546457 165.940157 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_8\">\n",
       "    <path clip-path=\"url(#pddc098e815)\" d=\"M 35.546457 222.633071 \n",
       "C 40.056998 222.633071 44.383406 220.841014 47.57284 217.65158 \n",
       "C 50.762274 214.462146 52.554331 210.135738 52.554331 205.625197 \n",
       "C 52.554331 201.114656 50.762274 196.788248 47.57284 193.598814 \n",
       "C 44.383406 190.40938 40.056998 188.617323 35.546457 188.617323 \n",
       "C 31.035916 188.617323 26.709508 190.40938 23.520074 193.598814 \n",
       "C 20.33064 196.788248 18.538583 201.114656 18.538583 205.625197 \n",
       "C 18.538583 210.135738 20.33064 214.462146 23.520074 217.65158 \n",
       "C 26.709508 220.841014 31.035916 222.633071 35.546457 222.633071 \n",
       "L 35.546457 222.633071 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_9\">\n",
       "    <path clip-path=\"url(#pddc098e815)\" d=\"M 35.546457 52.554331 \n",
       "C 40.056998 52.554331 44.383406 50.762274 47.57284 47.57284 \n",
       "C 50.762274 44.383406 52.554331 40.056998 52.554331 35.546457 \n",
       "C 52.554331 31.035916 50.762274 26.709508 47.57284 23.520074 \n",
       "C 44.383406 20.33064 40.056998 18.538583 35.546457 18.538583 \n",
       "C 31.035916 18.538583 26.709508 20.33064 23.520074 23.520074 \n",
       "C 20.33064 26.709508 18.538583 31.035916 18.538583 35.546457 \n",
       "C 18.538583 40.056998 20.33064 44.383406 23.520074 47.57284 \n",
       "C 26.709508 50.762274 31.035916 52.554331 35.546457 52.554331 \n",
       "L 35.546457 52.554331 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"matplotlib.axis_1\"/>\n",
       "   <g id=\"matplotlib.axis_2\"/>\n",
       "   <g id=\"text_1\">\n",
       "    <!-- $V_0$ -->\n",
       "    <defs>\n",
       "     <path d=\"M 47.703125 33 \n",
       "Q 47.703125 23.796875 45.546875 16.34375 \n",
       "Q 43.40625 8.90625 38.09375 3.75 \n",
       "Q 32.796875 -1.40625 25 -1.40625 \n",
       "Q 18.796875 -1.40625 14.25 1.6875 \n",
       "Q 9.703125 4.796875 7.203125 10.046875 \n",
       "Q 4.703125 15.296875 3.5 21.140625 \n",
       "Q 2.296875 27 2.296875 33.59375 \n",
       "Q 2.296875 42.90625 4.59375 50.34375 \n",
       "Q 6.90625 57.796875 12.296875 62.6875 \n",
       "Q 17.703125 67.59375 25.40625 67.59375 \n",
       "Q 35.203125 67.59375 41.453125 57.9375 \n",
       "Q 47.703125 48.296875 47.703125 33 \n",
       "M 39.796875 33 \n",
       "Q 39.796875 45.203125 35.75 52.84375 \n",
       "Q 31.703125 60.5 25.203125 60.5 \n",
       "Q 17.796875 60.5 14 52.75 \n",
       "Q 10.203125 45 10.203125 33.40625 \n",
       "Q 10.203125 28.203125 10.953125 23.546875 \n",
       "Q 11.703125 18.90625 13.34375 14.75 \n",
       "Q 15 10.59375 18 8.140625 \n",
       "Q 21 5.703125 25 5.703125 \n",
       "Q 30.09375 5.703125 33.546875 9.796875 \n",
       "Q 37 13.90625 38.390625 19.84375 \n",
       "Q 39.796875 25.796875 39.796875 33 \n",
       "\" id=\"STIXGeneral-Regular-1d7e2\"/>\n",
       "     <path d=\"M 78.796875 66.203125 \n",
       "L 33.703125 -1.09375 \n",
       "L 31.09375 -1.09375 \n",
       "L 19.59375 66.203125 \n",
       "L 29.09375 66.203125 \n",
       "L 36.796875 16.40625 \n",
       "L 69.203125 66.203125 \n",
       "z\n",
       "\" id=\"STIXGeneral-Italic-1d61d\"/>\n",
       "    </defs>\n",
       "    <g transform=\"translate(26.2764566929 97.2062450787)scale(0.18 -0.18)\">\n",
       "     <use transform=\"translate(0.0 0.796875)\" xlink:href=\"#STIXGeneral-Italic-1d61d\"/>\n",
       "     <use transform=\"translate(65.39999389648438 -12.792187499999997)scale(0.7)\" xlink:href=\"#STIXGeneral-Regular-1d7e2\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"text_2\">\n",
       "    <!-- $O_0$ -->\n",
       "    <defs>\n",
       "     <path d=\"M 77.90625 43 \n",
       "Q 77.90625 30.703125 71.546875 20.296875 \n",
       "Q 65.203125 9.90625 55.453125 4.25 \n",
       "Q 45.703125 -1.40625 35.296875 -1.40625 \n",
       "Q 23.703125 -1.40625 16.796875 5.25 \n",
       "Q 9.90625 11.90625 9.90625 23.203125 \n",
       "Q 9.90625 35.59375 16.25 46 \n",
       "Q 22.59375 56.40625 32.296875 62 \n",
       "Q 42 67.59375 52.5 67.59375 \n",
       "Q 64.09375 67.59375 71 60.9375 \n",
       "Q 77.90625 54.296875 77.90625 43 \n",
       "M 68.90625 42.09375 \n",
       "Q 68.90625 50.59375 64.15625 55.296875 \n",
       "Q 59.40625 60 50.59375 60 \n",
       "Q 39.59375 60 31.390625 52.75 \n",
       "Q 23.203125 45.5 20.09375 33.09375 \n",
       "Q 18.90625 28.203125 18.90625 24.09375 \n",
       "Q 18.90625 15.59375 23.65625 10.890625 \n",
       "Q 28.40625 6.203125 37.203125 6.203125 \n",
       "Q 48.203125 6.203125 56.390625 13.453125 \n",
       "Q 64.59375 20.703125 67.703125 33.09375 \n",
       "Q 68.90625 38.09375 68.90625 42.09375 \n",
       "\" id=\"STIXGeneral-Italic-1d616\"/>\n",
       "    </defs>\n",
       "    <g transform=\"translate(93.7679527559 182.245615157)scale(0.18 -0.18)\">\n",
       "     <use transform=\"translate(0.0 0.40625)\" xlink:href=\"#STIXGeneral-Italic-1d616\"/>\n",
       "     <use transform=\"translate(71.39999389648438 -13.182812499999997)scale(0.7)\" xlink:href=\"#STIXGeneral-Regular-1d7e2\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"text_3\">\n",
       "    <!-- $L_0$ -->\n",
       "    <defs>\n",
       "     <path d=\"M 56.40625 7.40625 \n",
       "L 52.796875 0 \n",
       "L 7.40625 0 \n",
       "L 23.90625 66.203125 \n",
       "L 32.59375 66.203125 \n",
       "L 17.90625 7.40625 \n",
       "z\n",
       "\" id=\"STIXGeneral-Italic-1d613\"/>\n",
       "    </defs>\n",
       "    <g transform=\"translate(27.0864566929 153.899158465)scale(0.18 -0.18)\">\n",
       "     <use transform=\"translate(0.0 0.796875)\" xlink:href=\"#STIXGeneral-Italic-1d613\"/>\n",
       "     <use transform=\"translate(55.899993896484375 -12.792187499999997)scale(0.7)\" xlink:href=\"#STIXGeneral-Regular-1d7e2\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"text_4\">\n",
       "    <!-- $F_0$ -->\n",
       "    <defs>\n",
       "     <path d=\"M 67.90625 66.203125 \n",
       "L 66.90625 58.796875 \n",
       "L 30.703125 58.796875 \n",
       "L 25.703125 38.59375 \n",
       "L 55.296875 38.59375 \n",
       "L 53.40625 31.09375 \n",
       "L 23.796875 31.09375 \n",
       "L 16.09375 0 \n",
       "L 7.40625 0 \n",
       "L 23.90625 66.203125 \n",
       "z\n",
       "\" id=\"STIXGeneral-Italic-1d60d\"/>\n",
       "    </defs>\n",
       "    <g transform=\"translate(27.3564566929 210.59207185)scale(0.18 -0.18)\">\n",
       "     <use transform=\"translate(0.0 0.796875)\" xlink:href=\"#STIXGeneral-Italic-1d60d\"/>\n",
       "     <use transform=\"translate(53.49998474121094 -12.792187499999997)scale(0.7)\" xlink:href=\"#STIXGeneral-Regular-1d7e2\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"text_5\">\n",
       "    <!-- $W_0$ -->\n",
       "    <defs>\n",
       "     <path d=\"M 105.703125 66.203125 \n",
       "L 66.09375 -1.09375 \n",
       "L 63.296875 -1.09375 \n",
       "L 56.59375 43.5 \n",
       "L 28.203125 -1.09375 \n",
       "L 25.40625 -1.09375 \n",
       "L 19.40625 66.203125 \n",
       "L 28.90625 66.203125 \n",
       "L 32.296875 18.59375 \n",
       "L 32.296875 18.796875 \n",
       "L 62.40625 66.203125 \n",
       "L 68.90625 18.59375 \n",
       "L 68.90625 18.796875 \n",
       "L 96.203125 66.203125 \n",
       "z\n",
       "\" id=\"STIXGeneral-Italic-1d61e\"/>\n",
       "    </defs>\n",
       "    <g transform=\"translate(23.8464566929 40.5133316929)scale(0.18 -0.18)\">\n",
       "     <use transform=\"translate(0.0 0.796875)\" xlink:href=\"#STIXGeneral-Italic-1d61e\"/>\n",
       "     <use transform=\"translate(92.09999084472656 -12.792187499999997)scale(0.7)\" xlink:href=\"#STIXGeneral-Regular-1d7e2\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "  </g>\n",
       " </g>\n",
       " <defs>\n",
       "  <clipPath id=\"pddc098e815\">\n",
       "   <rect height=\"226.771653543\" width=\"124.724409449\" x=\"7.2\" y=\"7.2\"/>\n",
       "  </clipPath>\n",
       " </defs>\n",
       "</svg>\n"
      ],
      "text/plain": [
       "<matplotlib.figure.Figure at 0x7feb96c96b00>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "pgm = daft.PGM([2.2, 4], origin=[-0.5, 0.5])\n",
    "add_node(pgm, 'W', '$W_0$', 0, 4)\n",
    "add_node(pgm, 'V', '$V_0$', 0, 3)\n",
    "add_node(pgm, 'L', '$L_0$', 0, 2)\n",
    "add_node(pgm, 'F', '$F_0$', 0, 1)\n",
    "add_node(pgm, 'O', '$O_0$', 1.2, 1.5)\n",
    "add_edges(pgm, [\n",
    "        ('L', 'V'),\n",
    "        ('L', 'O'),\n",
    "        ('F', 'O'),\n",
    "    ])\n",
    "pgm.render()\n",
    "save('bn_temporal_ex_01')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "image/svg+xml": [
       "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"no\"?>\n",
       "<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\n",
       "  \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n",
       "<!-- Created with matplotlib (http://matplotlib.org/) -->\n",
       "<svg height=\"241pt\" version=\"1.1\" viewBox=\"0 0 195 241\" width=\"195pt\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n",
       " <defs>\n",
       "  <style type=\"text/css\">\n",
       "*{stroke-linecap:butt;stroke-linejoin:round;stroke-miterlimit:100000;}\n",
       "  </style>\n",
       " </defs>\n",
       " <g id=\"figure_1\">\n",
       "  <g id=\"patch_1\">\n",
       "   <path d=\"M 0 241.171654 \n",
       "L 195.817323 241.171654 \n",
       "L 195.817323 -0 \n",
       "L 0 -0 \n",
       "L 0 241.171654 \n",
       "z\n",
       "\" style=\"fill:none;\"/>\n",
       "  </g>\n",
       "  <g id=\"axes_1\">\n",
       "   <g id=\"patch_2\">\n",
       "    <path clip-path=\"url(#p6192db3487)\" d=\"M 86.570079 35.546457 \n",
       "L 83.735433 37.672441 \n",
       "L 83.735433 35.546457 \n",
       "L 52.554331 35.546457 \n",
       "L 52.554331 35.546457 \n",
       "L 83.735433 35.546457 \n",
       "L 83.735433 33.420472 \n",
       "L 86.570079 35.546457 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_3\">\n",
       "    <path clip-path=\"url(#p6192db3487)\" d=\"M 90.512142 81.351194 \n",
       "L 86.973485 81.169725 \n",
       "L 88.334507 79.536499 \n",
       "L 48.612267 46.434632 \n",
       "L 48.612267 46.434632 \n",
       "L 88.334507 79.536499 \n",
       "L 89.695529 77.903272 \n",
       "L 90.512142 81.351194 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_4\">\n",
       "    <path clip-path=\"url(#p6192db3487)\" d=\"M 97.261387 189.833782 \n",
       "L 94.234699 187.991451 \n",
       "L 96.208626 187.20188 \n",
       "L 41.863023 51.337871 \n",
       "L 41.863023 51.337871 \n",
       "L 96.208626 187.20188 \n",
       "L 98.182553 186.412309 \n",
       "L 97.261387 189.833782 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_5\">\n",
       "    <path clip-path=\"url(#p6192db3487)\" d=\"M 86.570079 92.23937 \n",
       "L 83.735433 94.365354 \n",
       "L 83.735433 92.23937 \n",
       "L 52.554331 92.23937 \n",
       "L 52.554331 92.23937 \n",
       "L 83.735433 92.23937 \n",
       "L 83.735433 90.113386 \n",
       "L 86.570079 92.23937 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_6\">\n",
       "    <path clip-path=\"url(#p6192db3487)\" d=\"M 90.512142 138.044108 \n",
       "L 86.973485 137.862638 \n",
       "L 88.334507 136.229412 \n",
       "L 48.612267 103.127546 \n",
       "L 48.612267 103.127546 \n",
       "L 88.334507 136.229412 \n",
       "L 89.695529 134.596186 \n",
       "L 90.512142 138.044108 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_7\">\n",
       "    <path clip-path=\"url(#p6192db3487)\" d=\"M 86.570079 148.932283 \n",
       "L 83.735433 151.058268 \n",
       "L 83.735433 148.932283 \n",
       "L 52.554331 148.932283 \n",
       "L 52.554331 148.932283 \n",
       "L 83.735433 148.932283 \n",
       "L 83.735433 146.806299 \n",
       "L 86.570079 148.932283 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_8\">\n",
       "    <path clip-path=\"url(#p6192db3487)\" d=\"M 86.570079 205.625197 \n",
       "L 83.735433 207.751181 \n",
       "L 83.735433 205.625197 \n",
       "L 52.554331 205.625197 \n",
       "L 52.554331 205.625197 \n",
       "L 83.735433 205.625197 \n",
       "L 83.735433 203.499213 \n",
       "L 86.570079 205.625197 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_9\">\n",
       "    <path clip-path=\"url(#p6192db3487)\" d=\"M 145.058561 169.672588 \n",
       "L 141.572408 170.306434 \n",
       "L 142.523177 168.404896 \n",
       "L 118.790258 156.538436 \n",
       "L 118.790258 156.538436 \n",
       "L 142.523177 168.404896 \n",
       "L 143.473946 166.503357 \n",
       "L 145.058561 169.672588 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_10\">\n",
       "    <path clip-path=\"url(#p6192db3487)\" d=\"M 145.058561 184.884893 \n",
       "L 143.473946 188.054123 \n",
       "L 142.523177 186.152585 \n",
       "L 118.790258 198.019044 \n",
       "L 118.790258 198.019044 \n",
       "L 142.523177 186.152585 \n",
       "L 141.572408 184.251047 \n",
       "L 145.058561 184.884893 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_11\">\n",
       "    <path clip-path=\"url(#p6192db3487)\" d=\"M 35.546457 109.247244 \n",
       "L 37.672441 112.08189 \n",
       "L 35.546457 112.08189 \n",
       "L 35.546457 131.924409 \n",
       "L 35.546457 131.924409 \n",
       "L 35.546457 112.08189 \n",
       "L 33.420472 112.08189 \n",
       "L 35.546457 109.247244 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_12\">\n",
       "    <path clip-path=\"url(#p6192db3487)\" d=\"M 56.496394 166.390565 \n",
       "L 52.957737 166.209095 \n",
       "L 54.318759 164.575869 \n",
       "L 48.612267 159.820459 \n",
       "L 48.612267 159.820459 \n",
       "L 54.318759 164.575869 \n",
       "L 55.679781 162.942642 \n",
       "L 56.496394 166.390565 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_13\">\n",
       "    <path clip-path=\"url(#p6192db3487)\" d=\"M 56.496394 188.166916 \n",
       "L 55.679781 191.614838 \n",
       "L 54.318759 189.981612 \n",
       "L 48.612267 194.737021 \n",
       "L 48.612267 194.737021 \n",
       "L 54.318759 189.981612 \n",
       "L 52.957737 188.348385 \n",
       "L 56.496394 188.166916 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_14\">\n",
       "    <path clip-path=\"url(#p6192db3487)\" d=\"M 103.577953 52.554331 \n",
       "C 108.088494 52.554331 112.414902 50.762274 115.604336 47.57284 \n",
       "C 118.79377 44.383406 120.585827 40.056998 120.585827 35.546457 \n",
       "C 120.585827 31.035916 118.79377 26.709508 115.604336 23.520074 \n",
       "C 112.414902 20.33064 108.088494 18.538583 103.577953 18.538583 \n",
       "C 99.067412 18.538583 94.741004 20.33064 91.55157 23.520074 \n",
       "C 88.362136 26.709508 86.570079 31.035916 86.570079 35.546457 \n",
       "C 86.570079 40.056998 88.362136 44.383406 91.55157 47.57284 \n",
       "C 94.741004 50.762274 99.067412 52.554331 103.577953 52.554331 \n",
       "L 103.577953 52.554331 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_15\">\n",
       "    <path clip-path=\"url(#p6192db3487)\" d=\"M 69.562205 194.286614 \n",
       "C 74.072746 194.286614 78.399154 192.494557 81.588588 189.305123 \n",
       "C 84.778022 186.115689 86.570079 181.789281 86.570079 177.27874 \n",
       "C 86.570079 172.768199 84.778022 168.441791 81.588588 165.252357 \n",
       "C 78.399154 162.062923 74.072746 160.270866 69.562205 160.270866 \n",
       "C 65.051664 160.270866 60.725256 162.062923 57.535822 165.252357 \n",
       "C 54.346388 168.441791 52.554331 172.768199 52.554331 177.27874 \n",
       "C 52.554331 181.789281 54.346388 186.115689 57.535822 189.305123 \n",
       "C 60.725256 192.494557 65.051664 194.286614 69.562205 194.286614 \n",
       "L 69.562205 194.286614 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_16\">\n",
       "    <path clip-path=\"url(#p6192db3487)\" d=\"M 103.577953 165.940157 \n",
       "C 108.088494 165.940157 112.414902 164.148101 115.604336 160.958667 \n",
       "C 118.79377 157.769232 120.585827 153.442824 120.585827 148.932283 \n",
       "C 120.585827 144.421743 118.79377 140.095334 115.604336 136.9059 \n",
       "C 112.414902 133.716466 108.088494 131.924409 103.577953 131.924409 \n",
       "C 99.067412 131.924409 94.741004 133.716466 91.55157 136.9059 \n",
       "C 88.362136 140.095334 86.570079 144.421743 86.570079 148.932283 \n",
       "C 86.570079 153.442824 88.362136 157.769232 91.55157 160.958667 \n",
       "C 94.741004 164.148101 99.067412 165.940157 103.577953 165.940157 \n",
       "L 103.577953 165.940157 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_17\">\n",
       "    <path clip-path=\"url(#p6192db3487)\" d=\"M 103.577953 222.633071 \n",
       "C 108.088494 222.633071 112.414902 220.841014 115.604336 217.65158 \n",
       "C 118.79377 214.462146 120.585827 210.135738 120.585827 205.625197 \n",
       "C 120.585827 201.114656 118.79377 196.788248 115.604336 193.598814 \n",
       "C 112.414902 190.40938 108.088494 188.617323 103.577953 188.617323 \n",
       "C 99.067412 188.617323 94.741004 190.40938 91.55157 193.598814 \n",
       "C 88.362136 196.788248 86.570079 201.114656 86.570079 205.625197 \n",
       "C 86.570079 210.135738 88.362136 214.462146 91.55157 217.65158 \n",
       "C 94.741004 220.841014 99.067412 222.633071 103.577953 222.633071 \n",
       "L 103.577953 222.633071 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_18\">\n",
       "    <path clip-path=\"url(#p6192db3487)\" d=\"M 35.546457 109.247244 \n",
       "C 40.056998 109.247244 44.383406 107.455187 47.57284 104.265753 \n",
       "C 50.762274 101.076319 52.554331 96.749911 52.554331 92.23937 \n",
       "C 52.554331 87.728829 50.762274 83.402421 47.57284 80.212987 \n",
       "C 44.383406 77.023553 40.056998 75.231496 35.546457 75.231496 \n",
       "C 31.035916 75.231496 26.709508 77.023553 23.520074 80.212987 \n",
       "C 20.33064 83.402421 18.538583 87.728829 18.538583 92.23937 \n",
       "C 18.538583 96.749911 20.33064 101.076319 23.520074 104.265753 \n",
       "C 26.709508 107.455187 31.035916 109.247244 35.546457 109.247244 \n",
       "L 35.546457 109.247244 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_19\">\n",
       "    <path clip-path=\"url(#p6192db3487)\" d=\"M 35.546457 222.633071 \n",
       "C 40.056998 222.633071 44.383406 220.841014 47.57284 217.65158 \n",
       "C 50.762274 214.462146 52.554331 210.135738 52.554331 205.625197 \n",
       "C 52.554331 201.114656 50.762274 196.788248 47.57284 193.598814 \n",
       "C 44.383406 190.40938 40.056998 188.617323 35.546457 188.617323 \n",
       "C 31.035916 188.617323 26.709508 190.40938 23.520074 193.598814 \n",
       "C 20.33064 196.788248 18.538583 201.114656 18.538583 205.625197 \n",
       "C 18.538583 210.135738 20.33064 214.462146 23.520074 217.65158 \n",
       "C 26.709508 220.841014 31.035916 222.633071 35.546457 222.633071 \n",
       "L 35.546457 222.633071 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_20\">\n",
       "    <path clip-path=\"url(#p6192db3487)\" d=\"M 35.546457 165.940157 \n",
       "C 40.056998 165.940157 44.383406 164.148101 47.57284 160.958667 \n",
       "C 50.762274 157.769232 52.554331 153.442824 52.554331 148.932283 \n",
       "C 52.554331 144.421743 50.762274 140.095334 47.57284 136.9059 \n",
       "C 44.383406 133.716466 40.056998 131.924409 35.546457 131.924409 \n",
       "C 31.035916 131.924409 26.709508 133.716466 23.520074 136.9059 \n",
       "C 20.33064 140.095334 18.538583 144.421743 18.538583 148.932283 \n",
       "C 18.538583 153.442824 20.33064 157.769232 23.520074 160.958667 \n",
       "C 26.709508 164.148101 31.035916 165.940157 35.546457 165.940157 \n",
       "L 35.546457 165.940157 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_21\">\n",
       "    <path clip-path=\"url(#p6192db3487)\" d=\"M 103.577953 109.247244 \n",
       "C 108.088494 109.247244 112.414902 107.455187 115.604336 104.265753 \n",
       "C 118.79377 101.076319 120.585827 96.749911 120.585827 92.23937 \n",
       "C 120.585827 87.728829 118.79377 83.402421 115.604336 80.212987 \n",
       "C 112.414902 77.023553 108.088494 75.231496 103.577953 75.231496 \n",
       "C 99.067412 75.231496 94.741004 77.023553 91.55157 80.212987 \n",
       "C 88.362136 83.402421 86.570079 87.728829 86.570079 92.23937 \n",
       "C 86.570079 96.749911 88.362136 101.076319 91.55157 104.265753 \n",
       "C 94.741004 107.455187 99.067412 109.247244 103.577953 109.247244 \n",
       "L 103.577953 109.247244 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_22\">\n",
       "    <path clip-path=\"url(#p6192db3487)\" d=\"M 35.546457 52.554331 \n",
       "C 40.056998 52.554331 44.383406 50.762274 47.57284 47.57284 \n",
       "C 50.762274 44.383406 52.554331 40.056998 52.554331 35.546457 \n",
       "C 52.554331 31.035916 50.762274 26.709508 47.57284 23.520074 \n",
       "C 44.383406 20.33064 40.056998 18.538583 35.546457 18.538583 \n",
       "C 31.035916 18.538583 26.709508 20.33064 23.520074 23.520074 \n",
       "C 20.33064 26.709508 18.538583 31.035916 18.538583 35.546457 \n",
       "C 18.538583 40.056998 20.33064 44.383406 23.520074 47.57284 \n",
       "C 26.709508 50.762274 31.035916 52.554331 35.546457 52.554331 \n",
       "L 35.546457 52.554331 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_23\">\n",
       "    <path clip-path=\"url(#p6192db3487)\" d=\"M 160.270866 194.286614 \n",
       "C 164.781407 194.286614 169.107815 192.494557 172.297249 189.305123 \n",
       "C 175.486683 186.115689 177.27874 181.789281 177.27874 177.27874 \n",
       "C 177.27874 172.768199 175.486683 168.441791 172.297249 165.252357 \n",
       "C 169.107815 162.062923 164.781407 160.270866 160.270866 160.270866 \n",
       "C 155.760325 160.270866 151.433917 162.062923 148.244483 165.252357 \n",
       "C 145.055049 168.441791 143.262992 172.768199 143.262992 177.27874 \n",
       "C 143.262992 181.789281 145.055049 186.115689 148.244483 189.305123 \n",
       "C 151.433917 192.494557 155.760325 194.286614 160.270866 194.286614 \n",
       "L 160.270866 194.286614 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"matplotlib.axis_1\"/>\n",
       "   <g id=\"matplotlib.axis_2\"/>\n",
       "   <g id=\"text_1\">\n",
       "    <!-- $W_1$ -->\n",
       "    <defs>\n",
       "     <path d=\"M 105.703125 66.203125 \n",
       "L 66.09375 -1.09375 \n",
       "L 63.296875 -1.09375 \n",
       "L 56.59375 43.5 \n",
       "L 28.203125 -1.09375 \n",
       "L 25.40625 -1.09375 \n",
       "L 19.40625 66.203125 \n",
       "L 28.90625 66.203125 \n",
       "L 32.296875 18.59375 \n",
       "L 32.296875 18.796875 \n",
       "L 62.40625 66.203125 \n",
       "L 68.90625 18.59375 \n",
       "L 68.90625 18.796875 \n",
       "L 96.203125 66.203125 \n",
       "z\n",
       "\" id=\"STIXGeneral-Italic-1d61e\"/>\n",
       "     <path d=\"M 30.203125 0 \n",
       "L 22.296875 0 \n",
       "L 22.296875 57 \n",
       "Q 20.09375 56 15.75 53.75 \n",
       "Q 11.40625 51.5 10.796875 51.203125 \n",
       "L 10.796875 58.5 \n",
       "L 28.796875 67.703125 \n",
       "L 30.203125 67.203125 \n",
       "z\n",
       "\" id=\"STIXGeneral-Regular-1d7e3\"/>\n",
       "    </defs>\n",
       "    <g transform=\"translate(91.8779527559 40.5133316929)scale(0.18 -0.18)\">\n",
       "     <use transform=\"translate(0.0 0.796875)\" xlink:href=\"#STIXGeneral-Italic-1d61e\"/>\n",
       "     <use transform=\"translate(92.09999084472656 -12.792187499999997)scale(0.7)\" xlink:href=\"#STIXGeneral-Regular-1d7e3\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"text_2\">\n",
       "    <!-- $O_0$ -->\n",
       "    <defs>\n",
       "     <path d=\"M 47.703125 33 \n",
       "Q 47.703125 23.796875 45.546875 16.34375 \n",
       "Q 43.40625 8.90625 38.09375 3.75 \n",
       "Q 32.796875 -1.40625 25 -1.40625 \n",
       "Q 18.796875 -1.40625 14.25 1.6875 \n",
       "Q 9.703125 4.796875 7.203125 10.046875 \n",
       "Q 4.703125 15.296875 3.5 21.140625 \n",
       "Q 2.296875 27 2.296875 33.59375 \n",
       "Q 2.296875 42.90625 4.59375 50.34375 \n",
       "Q 6.90625 57.796875 12.296875 62.6875 \n",
       "Q 17.703125 67.59375 25.40625 67.59375 \n",
       "Q 35.203125 67.59375 41.453125 57.9375 \n",
       "Q 47.703125 48.296875 47.703125 33 \n",
       "M 39.796875 33 \n",
       "Q 39.796875 45.203125 35.75 52.84375 \n",
       "Q 31.703125 60.5 25.203125 60.5 \n",
       "Q 17.796875 60.5 14 52.75 \n",
       "Q 10.203125 45 10.203125 33.40625 \n",
       "Q 10.203125 28.203125 10.953125 23.546875 \n",
       "Q 11.703125 18.90625 13.34375 14.75 \n",
       "Q 15 10.59375 18 8.140625 \n",
       "Q 21 5.703125 25 5.703125 \n",
       "Q 30.09375 5.703125 33.546875 9.796875 \n",
       "Q 37 13.90625 38.390625 19.84375 \n",
       "Q 39.796875 25.796875 39.796875 33 \n",
       "\" id=\"STIXGeneral-Regular-1d7e2\"/>\n",
       "     <path d=\"M 77.90625 43 \n",
       "Q 77.90625 30.703125 71.546875 20.296875 \n",
       "Q 65.203125 9.90625 55.453125 4.25 \n",
       "Q 45.703125 -1.40625 35.296875 -1.40625 \n",
       "Q 23.703125 -1.40625 16.796875 5.25 \n",
       "Q 9.90625 11.90625 9.90625 23.203125 \n",
       "Q 9.90625 35.59375 16.25 46 \n",
       "Q 22.59375 56.40625 32.296875 62 \n",
       "Q 42 67.59375 52.5 67.59375 \n",
       "Q 64.09375 67.59375 71 60.9375 \n",
       "Q 77.90625 54.296875 77.90625 43 \n",
       "M 68.90625 42.09375 \n",
       "Q 68.90625 50.59375 64.15625 55.296875 \n",
       "Q 59.40625 60 50.59375 60 \n",
       "Q 39.59375 60 31.390625 52.75 \n",
       "Q 23.203125 45.5 20.09375 33.09375 \n",
       "Q 18.90625 28.203125 18.90625 24.09375 \n",
       "Q 18.90625 15.59375 23.65625 10.890625 \n",
       "Q 28.40625 6.203125 37.203125 6.203125 \n",
       "Q 48.203125 6.203125 56.390625 13.453125 \n",
       "Q 64.59375 20.703125 67.703125 33.09375 \n",
       "Q 68.90625 38.09375 68.90625 42.09375 \n",
       "\" id=\"STIXGeneral-Italic-1d616\"/>\n",
       "    </defs>\n",
       "    <g transform=\"translate(59.7522047244 182.245615157)scale(0.18 -0.18)\">\n",
       "     <use transform=\"translate(0.0 0.40625)\" xlink:href=\"#STIXGeneral-Italic-1d616\"/>\n",
       "     <use transform=\"translate(71.39999389648438 -13.182812499999997)scale(0.7)\" xlink:href=\"#STIXGeneral-Regular-1d7e2\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"text_3\">\n",
       "    <!-- $L_1$ -->\n",
       "    <defs>\n",
       "     <path d=\"M 56.40625 7.40625 \n",
       "L 52.796875 0 \n",
       "L 7.40625 0 \n",
       "L 23.90625 66.203125 \n",
       "L 32.59375 66.203125 \n",
       "L 17.90625 7.40625 \n",
       "z\n",
       "\" id=\"STIXGeneral-Italic-1d613\"/>\n",
       "    </defs>\n",
       "    <g transform=\"translate(95.1179527559 153.899158465)scale(0.18 -0.18)\">\n",
       "     <use transform=\"translate(0.0 0.796875)\" xlink:href=\"#STIXGeneral-Italic-1d613\"/>\n",
       "     <use transform=\"translate(55.899993896484375 -12.792187499999997)scale(0.7)\" xlink:href=\"#STIXGeneral-Regular-1d7e3\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"text_4\">\n",
       "    <!-- $F_1$ -->\n",
       "    <defs>\n",
       "     <path d=\"M 67.90625 66.203125 \n",
       "L 66.90625 58.796875 \n",
       "L 30.703125 58.796875 \n",
       "L 25.703125 38.59375 \n",
       "L 55.296875 38.59375 \n",
       "L 53.40625 31.09375 \n",
       "L 23.796875 31.09375 \n",
       "L 16.09375 0 \n",
       "L 7.40625 0 \n",
       "L 23.90625 66.203125 \n",
       "z\n",
       "\" id=\"STIXGeneral-Italic-1d60d\"/>\n",
       "    </defs>\n",
       "    <g transform=\"translate(95.3879527559 210.59207185)scale(0.18 -0.18)\">\n",
       "     <use transform=\"translate(0.0 0.796875)\" xlink:href=\"#STIXGeneral-Italic-1d60d\"/>\n",
       "     <use transform=\"translate(53.49998474121094 -12.792187499999997)scale(0.7)\" xlink:href=\"#STIXGeneral-Regular-1d7e3\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"text_5\">\n",
       "    <!-- $V_0$ -->\n",
       "    <defs>\n",
       "     <path d=\"M 78.796875 66.203125 \n",
       "L 33.703125 -1.09375 \n",
       "L 31.09375 -1.09375 \n",
       "L 19.59375 66.203125 \n",
       "L 29.09375 66.203125 \n",
       "L 36.796875 16.40625 \n",
       "L 69.203125 66.203125 \n",
       "z\n",
       "\" id=\"STIXGeneral-Italic-1d61d\"/>\n",
       "    </defs>\n",
       "    <g transform=\"translate(26.2764566929 97.2062450787)scale(0.18 -0.18)\">\n",
       "     <use transform=\"translate(0.0 0.796875)\" xlink:href=\"#STIXGeneral-Italic-1d61d\"/>\n",
       "     <use transform=\"translate(65.39999389648438 -12.792187499999997)scale(0.7)\" xlink:href=\"#STIXGeneral-Regular-1d7e2\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"text_6\">\n",
       "    <!-- $F_0$ -->\n",
       "    <g transform=\"translate(27.3564566929 210.59207185)scale(0.18 -0.18)\">\n",
       "     <use transform=\"translate(0.0 0.796875)\" xlink:href=\"#STIXGeneral-Italic-1d60d\"/>\n",
       "     <use transform=\"translate(53.49998474121094 -12.792187499999997)scale(0.7)\" xlink:href=\"#STIXGeneral-Regular-1d7e2\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"text_7\">\n",
       "    <!-- $L_0$ -->\n",
       "    <g transform=\"translate(27.0864566929 153.899158465)scale(0.18 -0.18)\">\n",
       "     <use transform=\"translate(0.0 0.796875)\" xlink:href=\"#STIXGeneral-Italic-1d613\"/>\n",
       "     <use transform=\"translate(55.899993896484375 -12.792187499999997)scale(0.7)\" xlink:href=\"#STIXGeneral-Regular-1d7e2\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"text_8\">\n",
       "    <!-- $V_1$ -->\n",
       "    <g transform=\"translate(94.3079527559 97.2062450787)scale(0.18 -0.18)\">\n",
       "     <use transform=\"translate(0.0 0.796875)\" xlink:href=\"#STIXGeneral-Italic-1d61d\"/>\n",
       "     <use transform=\"translate(65.39999389648438 -12.792187499999997)scale(0.7)\" xlink:href=\"#STIXGeneral-Regular-1d7e3\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"text_9\">\n",
       "    <!-- $W_0$ -->\n",
       "    <g transform=\"translate(23.8464566929 40.5133316929)scale(0.18 -0.18)\">\n",
       "     <use transform=\"translate(0.0 0.796875)\" xlink:href=\"#STIXGeneral-Italic-1d61e\"/>\n",
       "     <use transform=\"translate(92.09999084472656 -12.792187499999997)scale(0.7)\" xlink:href=\"#STIXGeneral-Regular-1d7e2\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"text_10\">\n",
       "    <!-- $O_1$ -->\n",
       "    <g transform=\"translate(150.460866142 182.245615157)scale(0.18 -0.18)\">\n",
       "     <use transform=\"translate(0.0 0.40625)\" xlink:href=\"#STIXGeneral-Italic-1d616\"/>\n",
       "     <use transform=\"translate(71.39999389648438 -13.182812499999997)scale(0.7)\" xlink:href=\"#STIXGeneral-Regular-1d7e3\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "  </g>\n",
       " </g>\n",
       " <defs>\n",
       "  <clipPath id=\"p6192db3487\">\n",
       "   <rect height=\"226.771653543\" width=\"181.417322835\" x=\"7.2\" y=\"7.2\"/>\n",
       "  </clipPath>\n",
       " </defs>\n",
       "</svg>\n"
      ],
      "text/plain": [
       "<matplotlib.figure.Figure at 0x7feb96b18400>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "pgm = daft.PGM([3.2, 4], origin=[-0.5, 0.5])\n",
    "add_node(pgm, 'W', '$W_0$', 0, 4)\n",
    "add_node(pgm, 'W_', '$W_1$', 1.2, 4)\n",
    "add_node(pgm, 'V', '$V_0$', 0, 3)\n",
    "add_node(pgm, 'V_', '$V_1$', 1.2, 3)\n",
    "add_node(pgm, 'L', '$L_0$', 0, 2)\n",
    "add_node(pgm, 'L_', '$L_1$', 1.2, 2)\n",
    "add_node(pgm, 'F', '$F_0$', 0, 1)\n",
    "add_node(pgm, 'F_', '$F_1$', 1.2, 1)\n",
    "add_node(pgm, 'O', '$O_0$', 0.6, 1.5)\n",
    "add_node(pgm, 'O_', '$O_1$', 2.2, 1.5)\n",
    "add_edges(pgm, [\n",
    "        ('W', 'W_'),\n",
    "        ('W', 'V_'),\n",
    "        ('W', 'F_'),\n",
    "        ('V', 'V_'),\n",
    "        ('V', 'L_'),\n",
    "        ('L', 'L_'),\n",
    "        ('F', 'F_'),\n",
    "        ('L_', 'O_'),\n",
    "        ('F_', 'O_'),\n",
    "        ('L', 'V'),\n",
    "        ('L', 'O'),\n",
    "        ('F', 'O')\n",
    "    ])\n",
    "pgm.render()\n",
    "save('bn_temporal_ex_02')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "image/svg+xml": [
       "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"no\"?>\n",
       "<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\n",
       "  \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n",
       "<!-- Created with matplotlib (http://matplotlib.org/) -->\n",
       "<svg height=\"127pt\" version=\"1.1\" viewBox=\"0 0 156 127\" width=\"156pt\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n",
       " <defs>\n",
       "  <style type=\"text/css\">\n",
       "*{stroke-linecap:butt;stroke-linejoin:round;stroke-miterlimit:100000;}\n",
       "  </style>\n",
       " </defs>\n",
       " <g id=\"figure_1\">\n",
       "  <g id=\"patch_1\">\n",
       "   <path d=\"M 0 127.785827 \n",
       "L 156.132283 127.785827 \n",
       "L 156.132283 0 \n",
       "L 0 0 \n",
       "L 0 127.785827 \n",
       "z\n",
       "\" style=\"fill:none;\"/>\n",
       "  </g>\n",
       "  <g id=\"axes_1\">\n",
       "   <g id=\"patch_2\">\n",
       "    <path clip-path=\"url(#p88ad1a4926)\" d=\"M 109.247244 35.546457 \n",
       "L 106.412598 37.672441 \n",
       "L 106.412598 35.546457 \n",
       "L 75.231496 35.546457 \n",
       "L 75.231496 35.546457 \n",
       "L 106.412598 35.546457 \n",
       "L 106.412598 33.420472 \n",
       "L 109.247244 35.546457 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_3\">\n",
       "    <path clip-path=\"url(#p88ad1a4926)\" d=\"M 126.255118 75.231496 \n",
       "L 124.129134 72.39685 \n",
       "L 126.255118 72.39685 \n",
       "L 126.255118 52.554331 \n",
       "L 126.255118 52.554331 \n",
       "L 126.255118 72.39685 \n",
       "L 128.381102 72.39685 \n",
       "L 126.255118 75.231496 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_4\">\n",
       "    <path clip-path=\"url(#p88ad1a4926)\" d=\"M 58.223622 52.554331 \n",
       "C 62.734163 52.554331 67.060571 50.762274 70.250005 47.57284 \n",
       "C 73.439439 44.383406 75.231496 40.056998 75.231496 35.546457 \n",
       "C 75.231496 31.035916 73.439439 26.709508 70.250005 23.520074 \n",
       "C 67.060571 20.33064 62.734163 18.538583 58.223622 18.538583 \n",
       "C 53.713081 18.538583 49.386673 20.33064 46.197239 23.520074 \n",
       "C 43.007805 26.709508 41.215748 31.035916 41.215748 35.546457 \n",
       "C 41.215748 40.056998 43.007805 44.383406 46.197239 47.57284 \n",
       "C 49.386673 50.762274 53.713081 52.554331 58.223622 52.554331 \n",
       "L 58.223622 52.554331 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_5\">\n",
       "    <path clip-path=\"url(#p88ad1a4926)\" d=\"M 126.255118 109.247244 \n",
       "C 130.765659 109.247244 135.092067 107.455187 138.281501 104.265753 \n",
       "C 141.470935 101.076319 143.262992 96.749911 143.262992 92.23937 \n",
       "C 143.262992 87.728829 141.470935 83.402421 138.281501 80.212987 \n",
       "C 135.092067 77.023553 130.765659 75.231496 126.255118 75.231496 \n",
       "C 121.744577 75.231496 117.418169 77.023553 114.228735 80.212987 \n",
       "C 111.039301 83.402421 109.247244 87.728829 109.247244 92.23937 \n",
       "C 109.247244 96.749911 111.039301 101.076319 114.228735 104.265753 \n",
       "C 117.418169 107.455187 121.744577 109.247244 126.255118 109.247244 \n",
       "L 126.255118 109.247244 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_6\">\n",
       "    <path clip-path=\"url(#p88ad1a4926)\" d=\"M 126.255118 52.554331 \n",
       "C 130.765659 52.554331 135.092067 50.762274 138.281501 47.57284 \n",
       "C 141.470935 44.383406 143.262992 40.056998 143.262992 35.546457 \n",
       "C 143.262992 31.035916 141.470935 26.709508 138.281501 23.520074 \n",
       "C 135.092067 20.33064 130.765659 18.538583 126.255118 18.538583 \n",
       "C 121.744577 18.538583 117.418169 20.33064 114.228735 23.520074 \n",
       "C 111.039301 26.709508 109.247244 31.035916 109.247244 35.546457 \n",
       "C 109.247244 40.056998 111.039301 44.383406 114.228735 47.57284 \n",
       "C 117.418169 50.762274 121.744577 52.554331 126.255118 52.554331 \n",
       "L 126.255118 52.554331 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"matplotlib.axis_1\"/>\n",
       "   <g id=\"matplotlib.axis_2\"/>\n",
       "   <g id=\"text_1\">\n",
       "    <!-- S -->\n",
       "    <defs>\n",
       "     <path d=\"M 53.515625 70.515625 \n",
       "L 53.515625 60.890625 \n",
       "Q 47.90625 63.578125 42.921875 64.890625 \n",
       "Q 37.9375 66.21875 33.296875 66.21875 \n",
       "Q 25.25 66.21875 20.875 63.09375 \n",
       "Q 16.5 59.96875 16.5 54.203125 \n",
       "Q 16.5 49.359375 19.40625 46.890625 \n",
       "Q 22.3125 44.4375 30.421875 42.921875 \n",
       "L 36.375 41.703125 \n",
       "Q 47.40625 39.59375 52.65625 34.296875 \n",
       "Q 57.90625 29 57.90625 20.125 \n",
       "Q 57.90625 9.515625 50.796875 4.046875 \n",
       "Q 43.703125 -1.421875 29.984375 -1.421875 \n",
       "Q 24.8125 -1.421875 18.96875 -0.25 \n",
       "Q 13.140625 0.921875 6.890625 3.21875 \n",
       "L 6.890625 13.375 \n",
       "Q 12.890625 10.015625 18.65625 8.296875 \n",
       "Q 24.421875 6.59375 29.984375 6.59375 \n",
       "Q 38.421875 6.59375 43.015625 9.90625 \n",
       "Q 47.609375 13.234375 47.609375 19.390625 \n",
       "Q 47.609375 24.75 44.3125 27.78125 \n",
       "Q 41.015625 30.8125 33.5 32.328125 \n",
       "L 27.484375 33.5 \n",
       "Q 16.453125 35.6875 11.515625 40.375 \n",
       "Q 6.59375 45.0625 6.59375 53.421875 \n",
       "Q 6.59375 63.09375 13.40625 68.65625 \n",
       "Q 20.21875 74.21875 32.171875 74.21875 \n",
       "Q 37.3125 74.21875 42.625 73.28125 \n",
       "Q 47.953125 72.359375 53.515625 70.515625 \n",
       "\" id=\"BitstreamVeraSans-Roman-53\"/>\n",
       "    </defs>\n",
       "    <g transform=\"translate(52.5100282972 40.5133316929)scale(0.18 -0.18)\">\n",
       "     <use xlink:href=\"#BitstreamVeraSans-Roman-53\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"text_2\">\n",
       "    <!-- O -->\n",
       "    <defs>\n",
       "     <path d=\"M 39.40625 66.21875 \n",
       "Q 28.65625 66.21875 22.328125 58.203125 \n",
       "Q 16.015625 50.203125 16.015625 36.375 \n",
       "Q 16.015625 22.609375 22.328125 14.59375 \n",
       "Q 28.65625 6.59375 39.40625 6.59375 \n",
       "Q 50.140625 6.59375 56.421875 14.59375 \n",
       "Q 62.703125 22.609375 62.703125 36.375 \n",
       "Q 62.703125 50.203125 56.421875 58.203125 \n",
       "Q 50.140625 66.21875 39.40625 66.21875 \n",
       "M 39.40625 74.21875 \n",
       "Q 54.734375 74.21875 63.90625 63.9375 \n",
       "Q 73.09375 53.65625 73.09375 36.375 \n",
       "Q 73.09375 19.140625 63.90625 8.859375 \n",
       "Q 54.734375 -1.421875 39.40625 -1.421875 \n",
       "Q 24.03125 -1.421875 14.8125 8.828125 \n",
       "Q 5.609375 19.09375 5.609375 36.375 \n",
       "Q 5.609375 53.65625 14.8125 63.9375 \n",
       "Q 24.03125 74.21875 39.40625 74.21875 \n",
       "\" id=\"BitstreamVeraSans-Roman-4f\"/>\n",
       "    </defs>\n",
       "    <g transform=\"translate(119.17043061 97.2062450787)scale(0.18 -0.18)\">\n",
       "     <use xlink:href=\"#BitstreamVeraSans-Roman-4f\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"text_3\">\n",
       "    <!-- S' -->\n",
       "    <defs>\n",
       "     <path d=\"M 17.921875 72.90625 \n",
       "L 17.921875 45.796875 \n",
       "L 9.625 45.796875 \n",
       "L 9.625 72.90625 \n",
       "z\n",
       "\" id=\"BitstreamVeraSans-Roman-27\"/>\n",
       "    </defs>\n",
       "    <g transform=\"translate(118.06793061 40.5133316929)scale(0.18 -0.18)\">\n",
       "     <use xlink:href=\"#BitstreamVeraSans-Roman-53\"/>\n",
       "     <use x=\"63.4765625\" xlink:href=\"#BitstreamVeraSans-Roman-27\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "  </g>\n",
       " </g>\n",
       " <defs>\n",
       "  <clipPath id=\"p88ad1a4926\">\n",
       "   <rect height=\"113.385826772\" width=\"141.732283465\" x=\"7.2\" y=\"7.2\"/>\n",
       "  </clipPath>\n",
       " </defs>\n",
       "</svg>\n"
      ],
      "text/plain": [
       "<matplotlib.figure.Figure at 0x7feb96d3fe10>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "pgm = daft.PGM([2.5, 2], origin=[-0.5, 0.5])\n",
    "add_node(pgm, 'S', 'S', 0.4, 2)\n",
    "add_node(pgm, 'S_', 'S\\'', 1.6, 2)\n",
    "add_node(pgm, 'O', 'O', 1.6, 1)\n",
    "add_edges(pgm, [\n",
    "        ('S', 'S_'),\n",
    "        ('S_', 'O'),\n",
    "    ])\n",
    "pgm.render()\n",
    "save('bn_simple_hmm')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "image/svg+xml": [
       "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"no\"?>\n",
       "<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\n",
       "  \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n",
       "<!-- Created with matplotlib (http://matplotlib.org/) -->\n",
       "<svg height=\"127pt\" version=\"1.1\" viewBox=\"0 0 297 127\" width=\"297pt\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n",
       " <defs>\n",
       "  <style type=\"text/css\">\n",
       "*{stroke-linecap:butt;stroke-linejoin:round;stroke-miterlimit:100000;}\n",
       "  </style>\n",
       " </defs>\n",
       " <g id=\"figure_1\">\n",
       "  <g id=\"patch_1\">\n",
       "   <path d=\"M 0 127.785827 \n",
       "L 297.864567 127.785827 \n",
       "L 297.864567 0 \n",
       "L 0 0 \n",
       "L 0 127.785827 \n",
       "z\n",
       "\" style=\"fill:none;\"/>\n",
       "  </g>\n",
       "  <g id=\"axes_1\">\n",
       "   <g id=\"patch_2\">\n",
       "    <path clip-path=\"url(#p3a606294b3)\" d=\"M 109.247244 35.546457 \n",
       "L 106.412598 37.672441 \n",
       "L 106.412598 35.546457 \n",
       "L 75.231496 35.546457 \n",
       "L 75.231496 35.546457 \n",
       "L 106.412598 35.546457 \n",
       "L 106.412598 33.420472 \n",
       "L 109.247244 35.546457 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_3\">\n",
       "    <path clip-path=\"url(#p3a606294b3)\" d=\"M 126.255118 75.231496 \n",
       "L 124.129134 72.39685 \n",
       "L 126.255118 72.39685 \n",
       "L 126.255118 52.554331 \n",
       "L 126.255118 52.554331 \n",
       "L 126.255118 72.39685 \n",
       "L 128.381102 72.39685 \n",
       "L 126.255118 75.231496 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_4\">\n",
       "    <path clip-path=\"url(#p3a606294b3)\" d=\"M 177.27874 35.546457 \n",
       "L 174.444094 37.672441 \n",
       "L 174.444094 35.546457 \n",
       "L 143.262992 35.546457 \n",
       "L 143.262992 35.546457 \n",
       "L 174.444094 35.546457 \n",
       "L 174.444094 33.420472 \n",
       "L 177.27874 35.546457 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_5\">\n",
       "    <path clip-path=\"url(#p3a606294b3)\" d=\"M 194.286614 75.231496 \n",
       "L 192.16063 72.39685 \n",
       "L 194.286614 72.39685 \n",
       "L 194.286614 52.554331 \n",
       "L 194.286614 52.554331 \n",
       "L 194.286614 72.39685 \n",
       "L 196.412598 72.39685 \n",
       "L 194.286614 75.231496 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_6\">\n",
       "    <path clip-path=\"url(#p3a606294b3)\" d=\"M 245.310236 35.546457 \n",
       "L 242.475591 37.672441 \n",
       "L 242.475591 35.546457 \n",
       "L 211.294488 35.546457 \n",
       "L 211.294488 35.546457 \n",
       "L 242.475591 35.546457 \n",
       "L 242.475591 33.420472 \n",
       "L 245.310236 35.546457 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_7\">\n",
       "    <path clip-path=\"url(#p3a606294b3)\" d=\"M 126.255118 109.247244 \n",
       "C 130.765659 109.247244 135.092067 107.455187 138.281501 104.265753 \n",
       "C 141.470935 101.076319 143.262992 96.749911 143.262992 92.23937 \n",
       "C 143.262992 87.728829 141.470935 83.402421 138.281501 80.212987 \n",
       "C 135.092067 77.023553 130.765659 75.231496 126.255118 75.231496 \n",
       "C 121.744577 75.231496 117.418169 77.023553 114.228735 80.212987 \n",
       "C 111.039301 83.402421 109.247244 87.728829 109.247244 92.23937 \n",
       "C 109.247244 96.749911 111.039301 101.076319 114.228735 104.265753 \n",
       "C 117.418169 107.455187 121.744577 109.247244 126.255118 109.247244 \n",
       "L 126.255118 109.247244 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_8\">\n",
       "    <path clip-path=\"url(#p3a606294b3)\" d=\"M 58.223622 52.554331 \n",
       "C 62.734163 52.554331 67.060571 50.762274 70.250005 47.57284 \n",
       "C 73.439439 44.383406 75.231496 40.056998 75.231496 35.546457 \n",
       "C 75.231496 31.035916 73.439439 26.709508 70.250005 23.520074 \n",
       "C 67.060571 20.33064 62.734163 18.538583 58.223622 18.538583 \n",
       "C 53.713081 18.538583 49.386673 20.33064 46.197239 23.520074 \n",
       "C 43.007805 26.709508 41.215748 31.035916 41.215748 35.546457 \n",
       "C 41.215748 40.056998 43.007805 44.383406 46.197239 47.57284 \n",
       "C 49.386673 50.762274 53.713081 52.554331 58.223622 52.554331 \n",
       "L 58.223622 52.554331 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_9\">\n",
       "    <path clip-path=\"url(#p3a606294b3)\" d=\"M 194.286614 52.554331 \n",
       "C 198.797155 52.554331 203.123563 50.762274 206.312997 47.57284 \n",
       "C 209.502431 44.383406 211.294488 40.056998 211.294488 35.546457 \n",
       "C 211.294488 31.035916 209.502431 26.709508 206.312997 23.520074 \n",
       "C 203.123563 20.33064 198.797155 18.538583 194.286614 18.538583 \n",
       "C 189.776073 18.538583 185.449665 20.33064 182.260231 23.520074 \n",
       "C 179.070797 26.709508 177.27874 31.035916 177.27874 35.546457 \n",
       "C 177.27874 40.056998 179.070797 44.383406 182.260231 47.57284 \n",
       "C 185.449665 50.762274 189.776073 52.554331 194.286614 52.554331 \n",
       "L 194.286614 52.554331 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_10\">\n",
       "    <path clip-path=\"url(#p3a606294b3)\" d=\"M 126.255118 52.554331 \n",
       "C 130.765659 52.554331 135.092067 50.762274 138.281501 47.57284 \n",
       "C 141.470935 44.383406 143.262992 40.056998 143.262992 35.546457 \n",
       "C 143.262992 31.035916 141.470935 26.709508 138.281501 23.520074 \n",
       "C 135.092067 20.33064 130.765659 18.538583 126.255118 18.538583 \n",
       "C 121.744577 18.538583 117.418169 20.33064 114.228735 23.520074 \n",
       "C 111.039301 26.709508 109.247244 31.035916 109.247244 35.546457 \n",
       "C 109.247244 40.056998 111.039301 44.383406 114.228735 47.57284 \n",
       "C 117.418169 50.762274 121.744577 52.554331 126.255118 52.554331 \n",
       "L 126.255118 52.554331 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_11\">\n",
       "    <path clip-path=\"url(#p3a606294b3)\" d=\"M 262.31811 52.554331 \n",
       "C 266.828651 52.554331 271.155059 50.762274 274.344493 47.57284 \n",
       "C 277.533927 44.383406 279.325984 40.056998 279.325984 35.546457 \n",
       "C 279.325984 31.035916 277.533927 26.709508 274.344493 23.520074 \n",
       "C 271.155059 20.33064 266.828651 18.538583 262.31811 18.538583 \n",
       "C 257.807569 18.538583 253.481161 20.33064 250.291727 23.520074 \n",
       "C 247.102293 26.709508 245.310236 31.035916 245.310236 35.546457 \n",
       "C 245.310236 40.056998 247.102293 44.383406 250.291727 47.57284 \n",
       "C 253.481161 50.762274 257.807569 52.554331 262.31811 52.554331 \n",
       "L 262.31811 52.554331 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_12\">\n",
       "    <path clip-path=\"url(#p3a606294b3)\" d=\"M 194.286614 109.247244 \n",
       "C 198.797155 109.247244 203.123563 107.455187 206.312997 104.265753 \n",
       "C 209.502431 101.076319 211.294488 96.749911 211.294488 92.23937 \n",
       "C 211.294488 87.728829 209.502431 83.402421 206.312997 80.212987 \n",
       "C 203.123563 77.023553 198.797155 75.231496 194.286614 75.231496 \n",
       "C 189.776073 75.231496 185.449665 77.023553 182.260231 80.212987 \n",
       "C 179.070797 83.402421 177.27874 87.728829 177.27874 92.23937 \n",
       "C 177.27874 96.749911 179.070797 101.076319 182.260231 104.265753 \n",
       "C 185.449665 107.455187 189.776073 109.247244 194.286614 109.247244 \n",
       "L 194.286614 109.247244 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"matplotlib.axis_1\"/>\n",
       "   <g id=\"matplotlib.axis_2\"/>\n",
       "   <g id=\"text_1\">\n",
       "    <!-- $O^1$ -->\n",
       "    <defs>\n",
       "     <path d=\"M 30.203125 0 \n",
       "L 22.296875 0 \n",
       "L 22.296875 57 \n",
       "Q 20.09375 56 15.75 53.75 \n",
       "Q 11.40625 51.5 10.796875 51.203125 \n",
       "L 10.796875 58.5 \n",
       "L 28.796875 67.703125 \n",
       "L 30.203125 67.203125 \n",
       "z\n",
       "\" id=\"STIXGeneral-Regular-1d7e3\"/>\n",
       "     <path d=\"M 77.90625 43 \n",
       "Q 77.90625 30.703125 71.546875 20.296875 \n",
       "Q 65.203125 9.90625 55.453125 4.25 \n",
       "Q 45.703125 -1.40625 35.296875 -1.40625 \n",
       "Q 23.703125 -1.40625 16.796875 5.25 \n",
       "Q 9.90625 11.90625 9.90625 23.203125 \n",
       "Q 9.90625 35.59375 16.25 46 \n",
       "Q 22.59375 56.40625 32.296875 62 \n",
       "Q 42 67.59375 52.5 67.59375 \n",
       "Q 64.09375 67.59375 71 60.9375 \n",
       "Q 77.90625 54.296875 77.90625 43 \n",
       "M 68.90625 42.09375 \n",
       "Q 68.90625 50.59375 64.15625 55.296875 \n",
       "Q 59.40625 60 50.59375 60 \n",
       "Q 39.59375 60 31.390625 52.75 \n",
       "Q 23.203125 45.5 20.09375 33.09375 \n",
       "Q 18.90625 28.203125 18.90625 24.09375 \n",
       "Q 18.90625 15.59375 23.65625 10.890625 \n",
       "Q 28.40625 6.203125 37.203125 6.203125 \n",
       "Q 48.203125 6.203125 56.390625 13.453125 \n",
       "Q 64.59375 20.703125 67.703125 33.09375 \n",
       "Q 68.90625 38.09375 68.90625 42.09375 \n",
       "\" id=\"STIXGeneral-Italic-1d616\"/>\n",
       "    </defs>\n",
       "    <g transform=\"translate(114.91511811 97.2062450787)scale(0.18 -0.18)\">\n",
       "     <use transform=\"translate(0.0 0.37031249999999716)\" xlink:href=\"#STIXGeneral-Italic-1d616\"/>\n",
       "     <use transform=\"translate(88.69163452148437 36.6078125)scale(0.7)\" xlink:href=\"#STIXGeneral-Regular-1d7e3\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"text_2\">\n",
       "    <!-- $S^0$ -->\n",
       "    <defs>\n",
       "     <path d=\"M 47.703125 33 \n",
       "Q 47.703125 23.796875 45.546875 16.34375 \n",
       "Q 43.40625 8.90625 38.09375 3.75 \n",
       "Q 32.796875 -1.40625 25 -1.40625 \n",
       "Q 18.796875 -1.40625 14.25 1.6875 \n",
       "Q 9.703125 4.796875 7.203125 10.046875 \n",
       "Q 4.703125 15.296875 3.5 21.140625 \n",
       "Q 2.296875 27 2.296875 33.59375 \n",
       "Q 2.296875 42.90625 4.59375 50.34375 \n",
       "Q 6.90625 57.796875 12.296875 62.6875 \n",
       "Q 17.703125 67.59375 25.40625 67.59375 \n",
       "Q 35.203125 67.59375 41.453125 57.9375 \n",
       "Q 47.703125 48.296875 47.703125 33 \n",
       "M 39.796875 33 \n",
       "Q 39.796875 45.203125 35.75 52.84375 \n",
       "Q 31.703125 60.5 25.203125 60.5 \n",
       "Q 17.796875 60.5 14 52.75 \n",
       "Q 10.203125 45 10.203125 33.40625 \n",
       "Q 10.203125 28.203125 10.953125 23.546875 \n",
       "Q 11.703125 18.90625 13.34375 14.75 \n",
       "Q 15 10.59375 18 8.140625 \n",
       "Q 21 5.703125 25 5.703125 \n",
       "Q 30.09375 5.703125 33.546875 9.796875 \n",
       "Q 37 13.90625 38.390625 19.84375 \n",
       "Q 39.796875 25.796875 39.796875 33 \n",
       "\" id=\"STIXGeneral-Regular-1d7e2\"/>\n",
       "     <path d=\"M 59.703125 59.59375 \n",
       "L 56.703125 47.703125 \n",
       "L 54.796875 47.703125 \n",
       "Q 53.90625 53.703125 49.90625 56.84375 \n",
       "Q 45.90625 60 40.09375 60 \n",
       "Q 35 60 30.953125 56.5 \n",
       "Q 26.90625 53 26.90625 48.796875 \n",
       "Q 26.90625 42.90625 38.09375 37.796875 \n",
       "Q 46 34.296875 49.453125 30.59375 \n",
       "Q 52.90625 26.90625 52.90625 21.90625 \n",
       "Q 52.90625 11.5 44.65625 5.046875 \n",
       "Q 36.40625 -1.40625 25.40625 -1.40625 \n",
       "Q 10.90625 -1.40625 6.203125 7 \n",
       "L 8.296875 20.5 \n",
       "L 10.09375 20.5 \n",
       "Q 11.5 13.203125 16.34375 9.703125 \n",
       "Q 21.203125 6.203125 26.90625 6.203125 \n",
       "Q 34.296875 6.203125 38.890625 9.75 \n",
       "Q 43.5 13.296875 43.5 18.59375 \n",
       "Q 43.5 21.90625 41.140625 24.34375 \n",
       "Q 38.796875 26.796875 33.59375 29.09375 \n",
       "Q 25.40625 32.796875 21.65625 36.640625 \n",
       "Q 17.90625 40.5 17.90625 45.59375 \n",
       "Q 17.90625 55 25.34375 61.296875 \n",
       "Q 32.796875 67.59375 42.5 67.59375 \n",
       "Q 54.90625 67.59375 59.703125 59.59375 \n",
       "\" id=\"STIXGeneral-Italic-1d61a\"/>\n",
       "    </defs>\n",
       "    <g transform=\"translate(48.4136220472 40.5133316929)scale(0.18 -0.18)\">\n",
       "     <use transform=\"translate(0.0 0.4468750000000057)\" xlink:href=\"#STIXGeneral-Italic-1d61a\"/>\n",
       "     <use transform=\"translate(71.39163146972656 36.68437500000001)scale(0.7)\" xlink:href=\"#STIXGeneral-Regular-1d7e2\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"text_3\">\n",
       "    <!-- $S^2$ -->\n",
       "    <defs>\n",
       "     <path d=\"M 46.90625 7.09375 \n",
       "L 44 0 \n",
       "L 3.5 0 \n",
       "L 3.5 2.09375 \n",
       "L 21 23.5 \n",
       "L 21 23.40625 \n",
       "L 26.59375 30.203125 \n",
       "Q 30.5 34.90625 32.09375 36.953125 \n",
       "Q 33.703125 39 35.203125 41.953125 \n",
       "Q 36.703125 44.90625 36.703125 47.5 \n",
       "Q 36.703125 53.703125 33.34375 57.09375 \n",
       "Q 30 60.5 24.203125 60.5 \n",
       "Q 19.59375 60.5 15.75 56.703125 \n",
       "Q 11.90625 52.90625 10.90625 45.90625 \n",
       "L 3.703125 47.59375 \n",
       "Q 5.296875 56.5 11.1875 62.046875 \n",
       "Q 17.09375 67.59375 24.90625 67.59375 \n",
       "Q 33.59375 67.59375 39.09375 62.1875 \n",
       "Q 44.59375 56.796875 44.59375 49.09375 \n",
       "Q 44.59375 43.5 42.5 39.453125 \n",
       "Q 40.40625 35.40625 33.703125 27 \n",
       "L 17.703125 7.09375 \n",
       "z\n",
       "\" id=\"STIXGeneral-Regular-1d7e4\"/>\n",
       "    </defs>\n",
       "    <g transform=\"translate(184.476614173 40.5133316929)scale(0.18 -0.18)\">\n",
       "     <use transform=\"translate(0.0 0.4468750000000057)\" xlink:href=\"#STIXGeneral-Italic-1d61a\"/>\n",
       "     <use transform=\"translate(71.39163146972656 36.68437500000001)scale(0.7)\" xlink:href=\"#STIXGeneral-Regular-1d7e4\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"text_4\">\n",
       "    <!-- $S^1$ -->\n",
       "    <g transform=\"translate(116.44511811 40.5133316929)scale(0.18 -0.18)\">\n",
       "     <use transform=\"translate(0.0 0.37031249999999716)\" xlink:href=\"#STIXGeneral-Italic-1d61a\"/>\n",
       "     <use transform=\"translate(71.39163146972656 36.6078125)scale(0.7)\" xlink:href=\"#STIXGeneral-Regular-1d7e3\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"text_5\">\n",
       "    <!-- $\\dots$ -->\n",
       "    <defs>\n",
       "     <path d=\"M 88.796875 4.296875 \n",
       "Q 88.796875 2.09375 87.140625 0.5 \n",
       "Q 85.5 -1.09375 83.203125 -1.09375 \n",
       "Q 80.90625 -1.09375 79.296875 0.5 \n",
       "Q 77.703125 2.09375 77.703125 4.390625 \n",
       "Q 77.703125 6.703125 79.34375 8.34375 \n",
       "Q 81 10 83.296875 10 \n",
       "Q 85.5 10 87.140625 8.296875 \n",
       "Q 88.796875 6.59375 88.796875 4.296875 \n",
       "M 55.5 4.296875 \n",
       "Q 55.5 2.09375 53.84375 0.5 \n",
       "Q 52.203125 -1.09375 49.890625 -1.09375 \n",
       "Q 47.59375 -1.09375 46 0.5 \n",
       "Q 44.40625 2.09375 44.40625 4.390625 \n",
       "Q 44.40625 6.703125 46.046875 8.34375 \n",
       "Q 47.703125 10 50 10 \n",
       "Q 52.203125 10 53.84375 8.296875 \n",
       "Q 55.5 6.59375 55.5 4.296875 \n",
       "M 22.203125 4.296875 \n",
       "Q 22.203125 2.09375 20.546875 0.5 \n",
       "Q 18.90625 -1.09375 16.59375 -1.09375 \n",
       "Q 14.296875 -1.09375 12.6875 0.5 \n",
       "Q 11.09375 2.09375 11.09375 4.390625 \n",
       "Q 11.09375 6.703125 12.75 8.34375 \n",
       "Q 14.40625 10 16.703125 10 \n",
       "Q 18.90625 10 20.546875 8.296875 \n",
       "Q 22.203125 6.59375 22.203125 4.296875 \n",
       "\" id=\"STIXGeneral-Regular-2026\"/>\n",
       "    </defs>\n",
       "    <g transform=\"translate(253.318110236 40.5133316929)scale(0.18 -0.18)\">\n",
       "     <use xlink:href=\"#STIXGeneral-Regular-2026\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"text_6\">\n",
       "    <!-- $O^2$ -->\n",
       "    <g transform=\"translate(182.946614173 97.2062450787)scale(0.18 -0.18)\">\n",
       "     <use transform=\"translate(0.0 0.4468750000000057)\" xlink:href=\"#STIXGeneral-Italic-1d616\"/>\n",
       "     <use transform=\"translate(88.69163452148437 36.68437500000001)scale(0.7)\" xlink:href=\"#STIXGeneral-Regular-1d7e4\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "  </g>\n",
       " </g>\n",
       " <defs>\n",
       "  <clipPath id=\"p3a606294b3\">\n",
       "   <rect height=\"113.385826772\" width=\"283.464566929\" x=\"7.2\" y=\"7.2\"/>\n",
       "  </clipPath>\n",
       " </defs>\n",
       "</svg>\n"
      ],
      "text/plain": [
       "<matplotlib.figure.Figure at 0x7feb96e3e6a0>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "pgm = daft.PGM([5, 2], origin=[-0.5, 0.5])\n",
    "add_node(pgm, 'S', '$S^0$', 0.4, 2)\n",
    "add_node(pgm, 'S1', '$S^1$', 1.6, 2)\n",
    "add_node(pgm, 'O1', '$O^1$', 1.6, 1)\n",
    "add_node(pgm, 'S2', '$S^2$', 2.8, 2)\n",
    "add_node(pgm, 'O2', '$O^2$', 2.8, 1)\n",
    "add_node(pgm, 'dots', '$\\dots$', 4, 2)\n",
    "add_edges(pgm, [\n",
    "        ('S', 'S1'),\n",
    "        ('S1', 'O1'),\n",
    "        ('S1', 'S2'),\n",
    "        ('S2', 'O2'),\n",
    "        ('S2', 'dots')\n",
    "    ])\n",
    "pgm.render()\n",
    "save('bn_simple_hmm_unrolled')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "image/svg+xml": [
       "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"no\"?>\n",
       "<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\n",
       "  \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n",
       "<!-- Created with matplotlib (http://matplotlib.org/) -->\n",
       "<svg height=\"184pt\" version=\"1.1\" viewBox=\"0 0 297 184\" width=\"297pt\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n",
       " <defs>\n",
       "  <style type=\"text/css\">\n",
       "*{stroke-linecap:butt;stroke-linejoin:round;stroke-miterlimit:100000;}\n",
       "  </style>\n",
       " </defs>\n",
       " <g id=\"figure_1\">\n",
       "  <g id=\"patch_1\">\n",
       "   <path d=\"M 0 184.47874 \n",
       "L 297.864567 184.47874 \n",
       "L 297.864567 0 \n",
       "L 0 0 \n",
       "L 0 184.47874 \n",
       "z\n",
       "\" style=\"fill:none;\"/>\n",
       "  </g>\n",
       "  <g id=\"axes_1\">\n",
       "   <g id=\"patch_2\">\n",
       "    <path clip-path=\"url(#pabd7b0e9ad)\" d=\"M 92.23937 148.932283 \n",
       "L 205.625197 148.932283 \n",
       "L 205.625197 35.546457 \n",
       "L 92.23937 35.546457 \n",
       "L 92.23937 148.932283 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_3\">\n",
       "    <path clip-path=\"url(#pabd7b0e9ad)\" d=\"M 109.247244 92.23937 \n",
       "L 106.412598 94.365354 \n",
       "L 106.412598 92.23937 \n",
       "L 75.231496 92.23937 \n",
       "L 75.231496 92.23937 \n",
       "L 106.412598 92.23937 \n",
       "L 106.412598 90.113386 \n",
       "L 109.247244 92.23937 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_4\">\n",
       "    <path clip-path=\"url(#pabd7b0e9ad)\" d=\"M 58.223622 109.247244 \n",
       "C 62.734163 109.247244 67.060571 107.455187 70.250005 104.265753 \n",
       "C 73.439439 101.076319 75.231496 96.749911 75.231496 92.23937 \n",
       "C 75.231496 87.728829 73.439439 83.402421 70.250005 80.212987 \n",
       "C 67.060571 77.023553 62.734163 75.231496 58.223622 75.231496 \n",
       "C 53.713081 75.231496 49.386673 77.023553 46.197239 80.212987 \n",
       "C 43.007805 83.402421 41.215748 87.728829 41.215748 92.23937 \n",
       "C 41.215748 96.749911 43.007805 101.076319 46.197239 104.265753 \n",
       "C 49.386673 107.455187 53.713081 109.247244 58.223622 109.247244 \n",
       "L 58.223622 109.247244 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_5\">\n",
       "    <path clip-path=\"url(#pabd7b0e9ad)\" d=\"M 126.255118 109.247244 \n",
       "C 130.765659 109.247244 135.092067 107.455187 138.281501 104.265753 \n",
       "C 141.470935 101.076319 143.262992 96.749911 143.262992 92.23937 \n",
       "C 143.262992 87.728829 141.470935 83.402421 138.281501 80.212987 \n",
       "C 135.092067 77.023553 130.765659 75.231496 126.255118 75.231496 \n",
       "C 121.744577 75.231496 117.418169 77.023553 114.228735 80.212987 \n",
       "C 111.039301 83.402421 109.247244 87.728829 109.247244 92.23937 \n",
       "C 109.247244 96.749911 111.039301 101.076319 114.228735 104.265753 \n",
       "C 117.418169 107.455187 121.744577 109.247244 126.255118 109.247244 \n",
       "L 126.255118 109.247244 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"matplotlib.axis_1\"/>\n",
       "   <g id=\"matplotlib.axis_2\"/>\n",
       "   <g id=\"text_1\">\n",
       "    <!-- tosses $t$ -->\n",
       "    <defs>\n",
       "     <path d=\"M 18.3125 70.21875 \n",
       "L 18.3125 54.6875 \n",
       "L 36.8125 54.6875 \n",
       "L 36.8125 47.703125 \n",
       "L 18.3125 47.703125 \n",
       "L 18.3125 18.015625 \n",
       "Q 18.3125 11.328125 20.140625 9.421875 \n",
       "Q 21.96875 7.515625 27.59375 7.515625 \n",
       "L 36.8125 7.515625 \n",
       "L 36.8125 0 \n",
       "L 27.59375 0 \n",
       "Q 17.1875 0 13.234375 3.875 \n",
       "Q 9.28125 7.765625 9.28125 18.015625 \n",
       "L 9.28125 47.703125 \n",
       "L 2.6875 47.703125 \n",
       "L 2.6875 54.6875 \n",
       "L 9.28125 54.6875 \n",
       "L 9.28125 70.21875 \n",
       "z\n",
       "\" id=\"BitstreamVeraSans-Roman-74\"/>\n",
       "     <path d=\"M 44.28125 53.078125 \n",
       "L 44.28125 44.578125 \n",
       "Q 40.484375 46.53125 36.375 47.5 \n",
       "Q 32.28125 48.484375 27.875 48.484375 \n",
       "Q 21.1875 48.484375 17.84375 46.4375 \n",
       "Q 14.5 44.390625 14.5 40.28125 \n",
       "Q 14.5 37.15625 16.890625 35.375 \n",
       "Q 19.28125 33.59375 26.515625 31.984375 \n",
       "L 29.59375 31.296875 \n",
       "Q 39.15625 29.25 43.1875 25.515625 \n",
       "Q 47.21875 21.78125 47.21875 15.09375 \n",
       "Q 47.21875 7.46875 41.1875 3.015625 \n",
       "Q 35.15625 -1.421875 24.609375 -1.421875 \n",
       "Q 20.21875 -1.421875 15.453125 -0.5625 \n",
       "Q 10.6875 0.296875 5.421875 2 \n",
       "L 5.421875 11.28125 \n",
       "Q 10.40625 8.6875 15.234375 7.390625 \n",
       "Q 20.0625 6.109375 24.8125 6.109375 \n",
       "Q 31.15625 6.109375 34.5625 8.28125 \n",
       "Q 37.984375 10.453125 37.984375 14.40625 \n",
       "Q 37.984375 18.0625 35.515625 20.015625 \n",
       "Q 33.0625 21.96875 24.703125 23.78125 \n",
       "L 21.578125 24.515625 \n",
       "Q 13.234375 26.265625 9.515625 29.90625 \n",
       "Q 5.8125 33.546875 5.8125 39.890625 \n",
       "Q 5.8125 47.609375 11.28125 51.796875 \n",
       "Q 16.75 56 26.8125 56 \n",
       "Q 31.78125 56 36.171875 55.265625 \n",
       "Q 40.578125 54.546875 44.28125 53.078125 \n",
       "\" id=\"BitstreamVeraSans-Roman-73\"/>\n",
       "     <path d=\"M 30.609375 48.390625 \n",
       "Q 23.390625 48.390625 19.1875 42.75 \n",
       "Q 14.984375 37.109375 14.984375 27.296875 \n",
       "Q 14.984375 17.484375 19.15625 11.84375 \n",
       "Q 23.34375 6.203125 30.609375 6.203125 \n",
       "Q 37.796875 6.203125 41.984375 11.859375 \n",
       "Q 46.1875 17.53125 46.1875 27.296875 \n",
       "Q 46.1875 37.015625 41.984375 42.703125 \n",
       "Q 37.796875 48.390625 30.609375 48.390625 \n",
       "M 30.609375 56 \n",
       "Q 42.328125 56 49.015625 48.375 \n",
       "Q 55.71875 40.765625 55.71875 27.296875 \n",
       "Q 55.71875 13.875 49.015625 6.21875 \n",
       "Q 42.328125 -1.421875 30.609375 -1.421875 \n",
       "Q 18.84375 -1.421875 12.171875 6.21875 \n",
       "Q 5.515625 13.875 5.515625 27.296875 \n",
       "Q 5.515625 40.765625 12.171875 48.375 \n",
       "Q 18.84375 56 30.609375 56 \n",
       "\" id=\"BitstreamVeraSans-Roman-6f\"/>\n",
       "     <path id=\"BitstreamVeraSans-Roman-20\"/>\n",
       "     <path d=\"M 37.59375 45.296875 \n",
       "L 35.90625 38.203125 \n",
       "L 25.5 38.203125 \n",
       "L 19.40625 13.703125 \n",
       "Q 18.796875 11.296875 18.796875 9.796875 \n",
       "Q 18.796875 6.09375 22.59375 6.09375 \n",
       "Q 26.203125 6.09375 29.59375 8.703125 \n",
       "L 30.796875 8.703125 \n",
       "L 27.796875 1.203125 \n",
       "Q 24.40625 -1 18.5 -1 \n",
       "Q 14.40625 -1 12.25 1.046875 \n",
       "Q 10.09375 3.09375 10.09375 6.703125 \n",
       "Q 10.09375 8.203125 10.59375 10.40625 \n",
       "L 17.59375 38.203125 \n",
       "L 9.59375 38.203125 \n",
       "L 10 39.90625 \n",
       "L 15.796875 45.296875 \n",
       "L 19.296875 45.296875 \n",
       "L 20.90625 51.703125 \n",
       "L 28.59375 58 \n",
       "L 30.40625 58 \n",
       "L 27.203125 45.296875 \n",
       "z\n",
       "\" id=\"STIXGeneral-Italic-1d635\"/>\n",
       "     <path d=\"M 56.203125 29.59375 \n",
       "L 56.203125 25.203125 \n",
       "L 14.890625 25.203125 \n",
       "Q 15.484375 15.921875 20.484375 11.0625 \n",
       "Q 25.484375 6.203125 34.421875 6.203125 \n",
       "Q 39.59375 6.203125 44.453125 7.46875 \n",
       "Q 49.3125 8.734375 54.109375 11.28125 \n",
       "L 54.109375 2.78125 \n",
       "Q 49.265625 0.734375 44.1875 -0.34375 \n",
       "Q 39.109375 -1.421875 33.890625 -1.421875 \n",
       "Q 20.796875 -1.421875 13.15625 6.1875 \n",
       "Q 5.515625 13.8125 5.515625 26.8125 \n",
       "Q 5.515625 40.234375 12.765625 48.109375 \n",
       "Q 20.015625 56 32.328125 56 \n",
       "Q 43.359375 56 49.78125 48.890625 \n",
       "Q 56.203125 41.796875 56.203125 29.59375 \n",
       "M 47.21875 32.234375 \n",
       "Q 47.125 39.59375 43.09375 43.984375 \n",
       "Q 39.0625 48.390625 32.421875 48.390625 \n",
       "Q 24.90625 48.390625 20.390625 44.140625 \n",
       "Q 15.875 39.890625 15.1875 32.171875 \n",
       "z\n",
       "\" id=\"BitstreamVeraSans-Roman-65\"/>\n",
       "    </defs>\n",
       "    <g transform=\"translate(97.2393700787 143.932283465)scale(0.18 -0.18)\">\n",
       "     <use transform=\"translate(0.0 0.78125)\" xlink:href=\"#BitstreamVeraSans-Roman-74\"/>\n",
       "     <use transform=\"translate(39.208984375 0.78125)\" xlink:href=\"#BitstreamVeraSans-Roman-6f\"/>\n",
       "     <use transform=\"translate(100.390625 0.78125)\" xlink:href=\"#BitstreamVeraSans-Roman-73\"/>\n",
       "     <use transform=\"translate(152.490234375 0.78125)\" xlink:href=\"#BitstreamVeraSans-Roman-73\"/>\n",
       "     <use transform=\"translate(204.58984375 0.78125)\" xlink:href=\"#BitstreamVeraSans-Roman-65\"/>\n",
       "     <use transform=\"translate(266.11328125 0.78125)\" xlink:href=\"#BitstreamVeraSans-Roman-73\"/>\n",
       "     <use transform=\"translate(318.212890625 0.78125)\" xlink:href=\"#BitstreamVeraSans-Roman-20\"/>\n",
       "     <use transform=\"translate(350.0 0.78125)\" xlink:href=\"#STIXGeneral-Italic-1d635\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"text_2\">\n",
       "    <!-- $\\theta$ -->\n",
       "    <defs>\n",
       "     <path d=\"M 51.09375 49 \n",
       "Q 51.09375 38 47.140625 26.5 \n",
       "Q 43.203125 15 36 7 \n",
       "Q 28.796875 -1 20.59375 -1 \n",
       "Q 13.40625 -1 9.953125 4.25 \n",
       "Q 6.5 9.5 6.5 18.40625 \n",
       "Q 6.5 24.59375 8.640625 32.84375 \n",
       "Q 10.796875 41.09375 14.546875 49.140625 \n",
       "Q 18.296875 57.203125 24.546875 62.75 \n",
       "Q 30.796875 68.296875 37.90625 68.296875 \n",
       "Q 44.703125 68.296875 47.890625 62.9375 \n",
       "Q 51.09375 57.59375 51.09375 49 \n",
       "M 17.296875 37.296875 \n",
       "L 41.90625 37.296875 \n",
       "Q 43.203125 43.5 43.203125 48.5 \n",
       "Q 43.203125 61.203125 36 61.203125 \n",
       "Q 30.5 61.203125 25.390625 54.09375 \n",
       "Q 20.296875 47 17.296875 37.296875 \n",
       "M 40.203125 30.203125 \n",
       "L 15.59375 30.203125 \n",
       "Q 14.40625 24.296875 14.40625 19.296875 \n",
       "Q 14.40625 6.09375 22.296875 6.09375 \n",
       "Q 27.796875 6.09375 32.4375 12.84375 \n",
       "Q 37.09375 19.59375 40.203125 30.203125 \n",
       "\" id=\"STIXNonUnicode-Italic-e1df\"/>\n",
       "    </defs>\n",
       "    <g transform=\"translate(53.5436220472 97.2062450787)scale(0.18 -0.18)\">\n",
       "     <use transform=\"translate(0.0 0.703125)\" xlink:href=\"#STIXNonUnicode-Italic-e1df\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"text_3\">\n",
       "    <!-- outcome -->\n",
       "    <defs>\n",
       "     <path d=\"M 48.78125 52.59375 \n",
       "L 48.78125 44.1875 \n",
       "Q 44.96875 46.296875 41.140625 47.34375 \n",
       "Q 37.3125 48.390625 33.40625 48.390625 \n",
       "Q 24.65625 48.390625 19.8125 42.84375 \n",
       "Q 14.984375 37.3125 14.984375 27.296875 \n",
       "Q 14.984375 17.28125 19.8125 11.734375 \n",
       "Q 24.65625 6.203125 33.40625 6.203125 \n",
       "Q 37.3125 6.203125 41.140625 7.25 \n",
       "Q 44.96875 8.296875 48.78125 10.40625 \n",
       "L 48.78125 2.09375 \n",
       "Q 45.015625 0.34375 40.984375 -0.53125 \n",
       "Q 36.96875 -1.421875 32.421875 -1.421875 \n",
       "Q 20.0625 -1.421875 12.78125 6.34375 \n",
       "Q 5.515625 14.109375 5.515625 27.296875 \n",
       "Q 5.515625 40.671875 12.859375 48.328125 \n",
       "Q 20.21875 56 33.015625 56 \n",
       "Q 37.15625 56 41.109375 55.140625 \n",
       "Q 45.0625 54.296875 48.78125 52.59375 \n",
       "\" id=\"BitstreamVeraSans-Roman-63\"/>\n",
       "     <path d=\"M 8.5 21.578125 \n",
       "L 8.5 54.6875 \n",
       "L 17.484375 54.6875 \n",
       "L 17.484375 21.921875 \n",
       "Q 17.484375 14.15625 20.5 10.265625 \n",
       "Q 23.53125 6.390625 29.59375 6.390625 \n",
       "Q 36.859375 6.390625 41.078125 11.03125 \n",
       "Q 45.3125 15.671875 45.3125 23.6875 \n",
       "L 45.3125 54.6875 \n",
       "L 54.296875 54.6875 \n",
       "L 54.296875 0 \n",
       "L 45.3125 0 \n",
       "L 45.3125 8.40625 \n",
       "Q 42.046875 3.421875 37.71875 1 \n",
       "Q 33.40625 -1.421875 27.6875 -1.421875 \n",
       "Q 18.265625 -1.421875 13.375 4.4375 \n",
       "Q 8.5 10.296875 8.5 21.578125 \n",
       "\" id=\"BitstreamVeraSans-Roman-75\"/>\n",
       "     <path d=\"M 52 44.1875 \n",
       "Q 55.375 50.25 60.0625 53.125 \n",
       "Q 64.75 56 71.09375 56 \n",
       "Q 79.640625 56 84.28125 50.015625 \n",
       "Q 88.921875 44.046875 88.921875 33.015625 \n",
       "L 88.921875 0 \n",
       "L 79.890625 0 \n",
       "L 79.890625 32.71875 \n",
       "Q 79.890625 40.578125 77.09375 44.375 \n",
       "Q 74.3125 48.1875 68.609375 48.1875 \n",
       "Q 61.625 48.1875 57.5625 43.546875 \n",
       "Q 53.515625 38.921875 53.515625 30.90625 \n",
       "L 53.515625 0 \n",
       "L 44.484375 0 \n",
       "L 44.484375 32.71875 \n",
       "Q 44.484375 40.625 41.703125 44.40625 \n",
       "Q 38.921875 48.1875 33.109375 48.1875 \n",
       "Q 26.21875 48.1875 22.15625 43.53125 \n",
       "Q 18.109375 38.875 18.109375 30.90625 \n",
       "L 18.109375 0 \n",
       "L 9.078125 0 \n",
       "L 9.078125 54.6875 \n",
       "L 18.109375 54.6875 \n",
       "L 18.109375 46.1875 \n",
       "Q 21.1875 51.21875 25.484375 53.609375 \n",
       "Q 29.78125 56 35.6875 56 \n",
       "Q 41.65625 56 45.828125 52.96875 \n",
       "Q 50 49.953125 52 44.1875 \n",
       "\" id=\"BitstreamVeraSans-Roman-6d\"/>\n",
       "    </defs>\n",
       "    <g transform=\"translate(110.89449311 94.1709325787)scale(0.07 -0.07)\">\n",
       "     <use xlink:href=\"#BitstreamVeraSans-Roman-6f\"/>\n",
       "     <use x=\"61.181640625\" xlink:href=\"#BitstreamVeraSans-Roman-75\"/>\n",
       "     <use x=\"124.560546875\" xlink:href=\"#BitstreamVeraSans-Roman-74\"/>\n",
       "     <use x=\"163.76953125\" xlink:href=\"#BitstreamVeraSans-Roman-63\"/>\n",
       "     <use x=\"218.75\" xlink:href=\"#BitstreamVeraSans-Roman-6f\"/>\n",
       "     <use x=\"279.931640625\" xlink:href=\"#BitstreamVeraSans-Roman-6d\"/>\n",
       "     <use x=\"377.34375\" xlink:href=\"#BitstreamVeraSans-Roman-65\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "  </g>\n",
       " </g>\n",
       " <defs>\n",
       "  <clipPath id=\"pabd7b0e9ad\">\n",
       "   <rect height=\"170.078740157\" width=\"283.464566929\" x=\"7.2\" y=\"7.2\"/>\n",
       "  </clipPath>\n",
       " </defs>\n",
       "</svg>\n"
      ],
      "text/plain": [
       "<matplotlib.figure.Figure at 0x7feb96e3ee10>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "pgm = daft.PGM([5, 3], origin=[-0.5, 0.5])\n",
    "add_node(pgm, 't', r'$\\theta$', 0.4, 2)\n",
    "add_node(pgm, 'o', 'outcome', 1.6, 2, label_params={'size':7})\n",
    "add_edges(pgm, [\n",
    "        ('t', 'o'),\n",
    "    ])\n",
    "pgm.add_plate(daft.Plate((1,1,2,2), label='tosses $t$'))\n",
    "pgm.render()\n",
    "save('bn_plate_model')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "image/svg+xml": [
       "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"no\"?>\n",
       "<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\n",
       "  \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n",
       "<!-- Created with matplotlib (http://matplotlib.org/) -->\n",
       "<svg height=\"127pt\" version=\"1.1\" viewBox=\"0 0 156 127\" width=\"156pt\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n",
       " <defs>\n",
       "  <style type=\"text/css\">\n",
       "*{stroke-linecap:butt;stroke-linejoin:round;stroke-miterlimit:100000;}\n",
       "  </style>\n",
       " </defs>\n",
       " <g id=\"figure_1\">\n",
       "  <g id=\"patch_1\">\n",
       "   <path d=\"M 0 127.785827 \n",
       "L 156.132283 127.785827 \n",
       "L 156.132283 0 \n",
       "L 0 0 \n",
       "L 0 127.785827 \n",
       "z\n",
       "\" style=\"fill:none;\"/>\n",
       "  </g>\n",
       "  <g id=\"axes_1\">\n",
       "   <g id=\"patch_2\">\n",
       "    <path clip-path=\"url(#pcdbfe48c61)\" d=\"M 47.57284 68.874404 \n",
       "L 48.073939 65.366709 \n",
       "L 49.577237 66.870007 \n",
       "L 68.874404 47.57284 \n",
       "L 68.874404 47.57284 \n",
       "L 49.577237 66.870007 \n",
       "L 51.080535 68.373305 \n",
       "L 47.57284 68.874404 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_3\">\n",
       "    <path clip-path=\"url(#pcdbfe48c61)\" d=\"M 114.228735 68.874404 \n",
       "L 110.72104 68.373305 \n",
       "L 112.224338 66.870007 \n",
       "L 92.92717 47.57284 \n",
       "L 92.92717 47.57284 \n",
       "L 112.224338 66.870007 \n",
       "L 113.727636 65.366709 \n",
       "L 114.228735 68.874404 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_4\">\n",
       "    <path clip-path=\"url(#pcdbfe48c61)\" d=\"M 80.900787 63.892913 \n",
       "L 78.774803 61.058268 \n",
       "L 80.900787 61.058268 \n",
       "L 80.900787 52.554331 \n",
       "L 80.900787 52.554331 \n",
       "L 80.900787 61.058268 \n",
       "L 83.026772 61.058268 \n",
       "L 80.900787 63.892913 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_5\">\n",
       "    <path clip-path=\"url(#pcdbfe48c61)\" d=\"M 126.255118 97.908661 \n",
       "C 130.765659 97.908661 135.092067 96.116605 138.281501 92.92717 \n",
       "C 141.470935 89.737736 143.262992 85.411328 143.262992 80.900787 \n",
       "C 143.262992 76.390246 141.470935 72.063838 138.281501 68.874404 \n",
       "C 135.092067 65.68497 130.765659 63.892913 126.255118 63.892913 \n",
       "C 121.744577 63.892913 117.418169 65.68497 114.228735 68.874404 \n",
       "C 111.039301 72.063838 109.247244 76.390246 109.247244 80.900787 \n",
       "C 109.247244 85.411328 111.039301 89.737736 114.228735 92.92717 \n",
       "C 117.418169 96.116605 121.744577 97.908661 126.255118 97.908661 \n",
       "L 126.255118 97.908661 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_6\">\n",
       "    <path clip-path=\"url(#pcdbfe48c61)\" d=\"M 80.900787 52.554331 \n",
       "C 85.411328 52.554331 89.737736 50.762274 92.92717 47.57284 \n",
       "C 96.116605 44.383406 97.908661 40.056998 97.908661 35.546457 \n",
       "C 97.908661 31.035916 96.116605 26.709508 92.92717 23.520074 \n",
       "C 89.737736 20.33064 85.411328 18.538583 80.900787 18.538583 \n",
       "C 76.390246 18.538583 72.063838 20.33064 68.874404 23.520074 \n",
       "C 65.68497 26.709508 63.892913 31.035916 63.892913 35.546457 \n",
       "C 63.892913 40.056998 65.68497 44.383406 68.874404 47.57284 \n",
       "C 72.063838 50.762274 76.390246 52.554331 80.900787 52.554331 \n",
       "L 80.900787 52.554331 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_7\">\n",
       "    <path clip-path=\"url(#pcdbfe48c61)\" d=\"M 35.546457 97.908661 \n",
       "C 40.056998 97.908661 44.383406 96.116605 47.57284 92.92717 \n",
       "C 50.762274 89.737736 52.554331 85.411328 52.554331 80.900787 \n",
       "C 52.554331 76.390246 50.762274 72.063838 47.57284 68.874404 \n",
       "C 44.383406 65.68497 40.056998 63.892913 35.546457 63.892913 \n",
       "C 31.035916 63.892913 26.709508 65.68497 23.520074 68.874404 \n",
       "C 20.33064 72.063838 18.538583 76.390246 18.538583 80.900787 \n",
       "C 18.538583 85.411328 20.33064 89.737736 23.520074 92.92717 \n",
       "C 26.709508 96.116605 31.035916 97.908661 35.546457 97.908661 \n",
       "L 35.546457 97.908661 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_8\">\n",
       "    <path clip-path=\"url(#pcdbfe48c61)\" d=\"M 80.900787 97.908661 \n",
       "C 85.411328 97.908661 89.737736 96.116605 92.92717 92.92717 \n",
       "C 96.116605 89.737736 97.908661 85.411328 97.908661 80.900787 \n",
       "C 97.908661 76.390246 96.116605 72.063838 92.92717 68.874404 \n",
       "C 89.737736 65.68497 85.411328 63.892913 80.900787 63.892913 \n",
       "C 76.390246 63.892913 72.063838 65.68497 68.874404 68.874404 \n",
       "C 65.68497 72.063838 63.892913 76.390246 63.892913 80.900787 \n",
       "C 63.892913 85.411328 65.68497 89.737736 68.874404 92.92717 \n",
       "C 72.063838 96.116605 76.390246 97.908661 80.900787 97.908661 \n",
       "L 80.900787 97.908661 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"matplotlib.axis_1\"/>\n",
       "   <g id=\"matplotlib.axis_2\"/>\n",
       "   <g id=\"text_1\">\n",
       "    <!-- $o(t_n)$ -->\n",
       "    <defs>\n",
       "     <path d=\"M 37.59375 45.296875 \n",
       "L 35.90625 38.203125 \n",
       "L 25.5 38.203125 \n",
       "L 19.40625 13.703125 \n",
       "Q 18.796875 11.296875 18.796875 9.796875 \n",
       "Q 18.796875 6.09375 22.59375 6.09375 \n",
       "Q 26.203125 6.09375 29.59375 8.703125 \n",
       "L 30.796875 8.703125 \n",
       "L 27.796875 1.203125 \n",
       "Q 24.40625 -1 18.5 -1 \n",
       "Q 14.40625 -1 12.25 1.046875 \n",
       "Q 10.09375 3.09375 10.09375 6.703125 \n",
       "Q 10.09375 8.203125 10.59375 10.40625 \n",
       "L 17.59375 38.203125 \n",
       "L 9.59375 38.203125 \n",
       "L 10 39.90625 \n",
       "L 15.796875 45.296875 \n",
       "L 19.296875 45.296875 \n",
       "L 20.90625 51.703125 \n",
       "L 28.59375 58 \n",
       "L 30.40625 58 \n",
       "L 27.203125 45.296875 \n",
       "z\n",
       "\" id=\"STIXGeneral-Italic-1d635\"/>\n",
       "     <path d=\"M 30.40625 -16.09375 \n",
       "L 29.203125 -17.703125 \n",
       "Q 17.59375 -11.09375 11.1875 0.5 \n",
       "Q 4.796875 12.09375 4.796875 25.203125 \n",
       "Q 4.796875 52.90625 29.5 67.59375 \n",
       "L 30.40625 66 \n",
       "Q 20.203125 57.296875 16.796875 48.84375 \n",
       "Q 13.40625 40.40625 13.40625 25.5 \n",
       "Q 13.40625 10.703125 16.90625 1.5 \n",
       "Q 20.40625 -7.703125 30.40625 -16.09375 \n",
       "\" id=\"STIXGeneral-Regular-28\"/>\n",
       "     <path d=\"M 53.59375 30 \n",
       "Q 53.59375 25.09375 51.546875 19.6875 \n",
       "Q 49.5 14.296875 45.890625 9.640625 \n",
       "Q 42.296875 5 36.640625 2 \n",
       "Q 31 -1 24.5 -1 \n",
       "Q 16.59375 -1 12.09375 3.703125 \n",
       "Q 7.59375 8.40625 7.59375 16 \n",
       "Q 7.59375 27.5 16.046875 36.890625 \n",
       "Q 24.5 46.296875 36 46.296875 \n",
       "Q 44.203125 46.296875 48.890625 42 \n",
       "Q 53.59375 37.703125 53.59375 30 \n",
       "M 45.5 28.203125 \n",
       "Q 45.5 33.40625 42.546875 36.296875 \n",
       "Q 39.59375 39.203125 34.296875 39.203125 \n",
       "Q 26.796875 39.203125 21.25 32.5 \n",
       "Q 15.703125 25.796875 15.703125 17.703125 \n",
       "Q 15.703125 12.40625 18.546875 9.25 \n",
       "Q 21.40625 6.09375 26.40625 6.09375 \n",
       "Q 31.203125 6.09375 35.09375 8.6875 \n",
       "Q 39 11.296875 41.140625 15 \n",
       "Q 43.296875 18.703125 44.390625 22.203125 \n",
       "Q 45.5 25.703125 45.5 28.203125 \n",
       "\" id=\"STIXGeneral-Italic-1d630\"/>\n",
       "     <path d=\"M 2.90625 66 \n",
       "L 4.09375 67.59375 \n",
       "Q 15.5 60.796875 22 49.1875 \n",
       "Q 28.5 37.59375 28.5 24.703125 \n",
       "Q 28.5 -2.59375 3.796875 -17.703125 \n",
       "L 2.90625 -16.09375 \n",
       "Q 13.203125 -7.59375 16.546875 0.84375 \n",
       "Q 19.90625 9.296875 19.90625 24.40625 \n",
       "Q 19.90625 39.59375 16.546875 48.75 \n",
       "Q 13.203125 57.90625 2.90625 66 \n",
       "\" id=\"STIXGeneral-Regular-29\"/>\n",
       "     <path d=\"M 25.09375 45.90625 \n",
       "L 23.90625 40.203125 \n",
       "Q 28.40625 43.796875 32.203125 45.046875 \n",
       "Q 36 46.296875 40.5 46.296875 \n",
       "Q 45.203125 46.296875 48.09375 43.75 \n",
       "Q 51 41.203125 51 37.203125 \n",
       "Q 51 34.796875 50.40625 32.09375 \n",
       "L 42.40625 0 \n",
       "L 34.5 0 \n",
       "L 42 30.40625 \n",
       "Q 42.5 32.59375 42.5 33.90625 \n",
       "Q 42.5 39.203125 36 39.203125 \n",
       "Q 33.09375 39.203125 28.640625 36.703125 \n",
       "Q 24.203125 34.203125 21.703125 30.203125 \n",
       "L 14.203125 0 \n",
       "L 6.296875 0 \n",
       "L 17.203125 44 \n",
       "L 24.296875 46.40625 \n",
       "z\n",
       "\" id=\"STIXGeneral-Italic-1d62f\"/>\n",
       "    </defs>\n",
       "    <g transform=\"translate(113.51511811 84.7639124016)scale(0.14 -0.14)\">\n",
       "     <use transform=\"translate(0.0 0.40625)\" xlink:href=\"#STIXGeneral-Italic-1d630\"/>\n",
       "     <use transform=\"translate(49.899993896484375 0.40625)\" xlink:href=\"#STIXGeneral-Regular-28\"/>\n",
       "     <use transform=\"translate(83.19998168945312 0.40625)\" xlink:href=\"#STIXGeneral-Italic-1d635\"/>\n",
       "     <use transform=\"translate(112.29997253417969 -13.182812499999997)scale(0.7)\" xlink:href=\"#STIXGeneral-Italic-1d62f\"/>\n",
       "     <use transform=\"translate(148.6548141479492 0.40625)\" xlink:href=\"#STIXGeneral-Regular-29\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"text_2\">\n",
       "    <!-- $\\theta$ -->\n",
       "    <defs>\n",
       "     <path d=\"M 51.09375 49 \n",
       "Q 51.09375 38 47.140625 26.5 \n",
       "Q 43.203125 15 36 7 \n",
       "Q 28.796875 -1 20.59375 -1 \n",
       "Q 13.40625 -1 9.953125 4.25 \n",
       "Q 6.5 9.5 6.5 18.40625 \n",
       "Q 6.5 24.59375 8.640625 32.84375 \n",
       "Q 10.796875 41.09375 14.546875 49.140625 \n",
       "Q 18.296875 57.203125 24.546875 62.75 \n",
       "Q 30.796875 68.296875 37.90625 68.296875 \n",
       "Q 44.703125 68.296875 47.890625 62.9375 \n",
       "Q 51.09375 57.59375 51.09375 49 \n",
       "M 17.296875 37.296875 \n",
       "L 41.90625 37.296875 \n",
       "Q 43.203125 43.5 43.203125 48.5 \n",
       "Q 43.203125 61.203125 36 61.203125 \n",
       "Q 30.5 61.203125 25.390625 54.09375 \n",
       "Q 20.296875 47 17.296875 37.296875 \n",
       "M 40.203125 30.203125 \n",
       "L 15.59375 30.203125 \n",
       "Q 14.40625 24.296875 14.40625 19.296875 \n",
       "Q 14.40625 6.09375 22.296875 6.09375 \n",
       "Q 27.796875 6.09375 32.4375 12.84375 \n",
       "Q 37.09375 19.59375 40.203125 30.203125 \n",
       "\" id=\"STIXNonUnicode-Italic-e1df\"/>\n",
       "    </defs>\n",
       "    <g transform=\"translate(76.2207874016 40.5133316929)scale(0.18 -0.18)\">\n",
       "     <use transform=\"translate(0.0 0.703125)\" xlink:href=\"#STIXNonUnicode-Italic-e1df\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"text_3\">\n",
       "    <!-- $o(t_1)$ -->\n",
       "    <defs>\n",
       "     <path d=\"M 30.203125 0 \n",
       "L 22.296875 0 \n",
       "L 22.296875 57 \n",
       "Q 20.09375 56 15.75 53.75 \n",
       "Q 11.40625 51.5 10.796875 51.203125 \n",
       "L 10.796875 58.5 \n",
       "L 28.796875 67.703125 \n",
       "L 30.203125 67.203125 \n",
       "z\n",
       "\" id=\"STIXGeneral-Regular-1d7e3\"/>\n",
       "    </defs>\n",
       "    <g transform=\"translate(22.7364566929 84.7639124016)scale(0.14 -0.14)\">\n",
       "     <use transform=\"translate(0.0 0.40625)\" xlink:href=\"#STIXGeneral-Italic-1d630\"/>\n",
       "     <use transform=\"translate(49.899993896484375 0.40625)\" xlink:href=\"#STIXGeneral-Regular-28\"/>\n",
       "     <use transform=\"translate(83.19998168945312 0.40625)\" xlink:href=\"#STIXGeneral-Italic-1d635\"/>\n",
       "     <use transform=\"translate(112.29997253417969 -13.182812499999997)scale(0.7)\" xlink:href=\"#STIXGeneral-Regular-1d7e3\"/>\n",
       "     <use transform=\"translate(149.56480560302734 0.40625)\" xlink:href=\"#STIXGeneral-Regular-29\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"text_4\">\n",
       "    <!-- $\\dots$ -->\n",
       "    <defs>\n",
       "     <path d=\"M 88.796875 4.296875 \n",
       "Q 88.796875 2.09375 87.140625 0.5 \n",
       "Q 85.5 -1.09375 83.203125 -1.09375 \n",
       "Q 80.90625 -1.09375 79.296875 0.5 \n",
       "Q 77.703125 2.09375 77.703125 4.390625 \n",
       "Q 77.703125 6.703125 79.34375 8.34375 \n",
       "Q 81 10 83.296875 10 \n",
       "Q 85.5 10 87.140625 8.296875 \n",
       "Q 88.796875 6.59375 88.796875 4.296875 \n",
       "M 55.5 4.296875 \n",
       "Q 55.5 2.09375 53.84375 0.5 \n",
       "Q 52.203125 -1.09375 49.890625 -1.09375 \n",
       "Q 47.59375 -1.09375 46 0.5 \n",
       "Q 44.40625 2.09375 44.40625 4.390625 \n",
       "Q 44.40625 6.703125 46.046875 8.34375 \n",
       "Q 47.703125 10 50 10 \n",
       "Q 52.203125 10 53.84375 8.296875 \n",
       "Q 55.5 6.59375 55.5 4.296875 \n",
       "M 22.203125 4.296875 \n",
       "Q 22.203125 2.09375 20.546875 0.5 \n",
       "Q 18.90625 -1.09375 16.59375 -1.09375 \n",
       "Q 14.296875 -1.09375 12.6875 0.5 \n",
       "Q 11.09375 2.09375 11.09375 4.390625 \n",
       "Q 11.09375 6.703125 12.75 8.34375 \n",
       "Q 14.40625 10 16.703125 10 \n",
       "Q 18.90625 10 20.546875 8.296875 \n",
       "Q 22.203125 6.59375 22.203125 4.296875 \n",
       "\" id=\"STIXGeneral-Regular-2026\"/>\n",
       "    </defs>\n",
       "    <g transform=\"translate(71.9007874016 85.8676624016)scale(0.18 -0.18)\">\n",
       "     <use xlink:href=\"#STIXGeneral-Regular-2026\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "  </g>\n",
       " </g>\n",
       " <defs>\n",
       "  <clipPath id=\"pcdbfe48c61\">\n",
       "   <rect height=\"113.385826772\" width=\"141.732283465\" x=\"7.2\" y=\"7.2\"/>\n",
       "  </clipPath>\n",
       " </defs>\n",
       "</svg>\n"
      ],
      "text/plain": [
       "<matplotlib.figure.Figure at 0x7feb96bfbf28>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "pgm = daft.PGM([2.5, 2], origin=[-0.5, 0.5])\n",
    "add_node(pgm, 'o1', '$o(t_1)$', 0, 1.2, label_params={'size':14})\n",
    "add_node(pgm, 't', r'$\\theta$', 0.8, 2)\n",
    "add_node(pgm, 'd', '$\\dots$', 0.8, 1.2)\n",
    "add_node(pgm, 'on', '$o(t_n)$', 1.6, 1.2, label_params={'size':14})\n",
    "add_edges(pgm, [\n",
    "        ('t', 'o1'),\n",
    "        ('t', 'on'),\n",
    "        ('t', 'd')\n",
    "    ])\n",
    "pgm.render()\n",
    "save('bn_plate_model_alt')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "image/svg+xml": [
       "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"no\"?>\n",
       "<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\n",
       "  \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n",
       "<!-- Created with matplotlib (http://matplotlib.org/) -->\n",
       "<svg height=\"241pt\" version=\"1.1\" viewBox=\"0 0 241 241\" width=\"241pt\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n",
       " <defs>\n",
       "  <style type=\"text/css\">\n",
       "*{stroke-linecap:butt;stroke-linejoin:round;stroke-miterlimit:100000;}\n",
       "  </style>\n",
       " </defs>\n",
       " <g id=\"figure_1\">\n",
       "  <g id=\"patch_1\">\n",
       "   <path d=\"M 0 241.171654 \n",
       "L 241.171654 241.171654 \n",
       "L 241.171654 -0 \n",
       "L 0 -0 \n",
       "L 0 241.171654 \n",
       "z\n",
       "\" style=\"fill:none;\"/>\n",
       "  </g>\n",
       "  <g id=\"axes_1\">\n",
       "   <g id=\"patch_2\">\n",
       "    <path clip-path=\"url(#pedb8c93ab8)\" d=\"M 92.23937 205.625197 \n",
       "L 205.625197 205.625197 \n",
       "L 205.625197 63.892913 \n",
       "L 92.23937 63.892913 \n",
       "L 92.23937 205.625197 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_3\">\n",
       "    <path clip-path=\"url(#pedb8c93ab8)\" d=\"M 109.247244 92.23937 \n",
       "L 106.412598 94.365354 \n",
       "L 106.412598 92.23937 \n",
       "L 75.231496 92.23937 \n",
       "L 75.231496 92.23937 \n",
       "L 106.412598 92.23937 \n",
       "L 106.412598 90.113386 \n",
       "L 109.247244 92.23937 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_4\">\n",
       "    <path clip-path=\"url(#pedb8c93ab8)\" d=\"M 109.247244 148.932283 \n",
       "L 106.412598 151.058268 \n",
       "L 106.412598 148.932283 \n",
       "L 75.231496 148.932283 \n",
       "L 75.231496 148.932283 \n",
       "L 106.412598 148.932283 \n",
       "L 106.412598 146.806299 \n",
       "L 109.247244 148.932283 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_5\">\n",
       "    <path clip-path=\"url(#pedb8c93ab8)\" d=\"M 126.255118 131.924409 \n",
       "L 124.129134 129.089764 \n",
       "L 126.255118 129.089764 \n",
       "L 126.255118 109.247244 \n",
       "L 126.255118 109.247244 \n",
       "L 126.255118 129.089764 \n",
       "L 128.381102 129.089764 \n",
       "L 126.255118 131.924409 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_6\">\n",
       "    <path clip-path=\"url(#pedb8c93ab8)\" d=\"M 126.255118 109.247244 \n",
       "C 130.765659 109.247244 135.092067 107.455187 138.281501 104.265753 \n",
       "C 141.470935 101.076319 143.262992 96.749911 143.262992 92.23937 \n",
       "C 143.262992 87.728829 141.470935 83.402421 138.281501 80.212987 \n",
       "C 135.092067 77.023553 130.765659 75.231496 126.255118 75.231496 \n",
       "C 121.744577 75.231496 117.418169 77.023553 114.228735 80.212987 \n",
       "C 111.039301 83.402421 109.247244 87.728829 109.247244 92.23937 \n",
       "C 109.247244 96.749911 111.039301 101.076319 114.228735 104.265753 \n",
       "C 117.418169 107.455187 121.744577 109.247244 126.255118 109.247244 \n",
       "L 126.255118 109.247244 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_7\">\n",
       "    <path clip-path=\"url(#pedb8c93ab8)\" d=\"M 58.223622 109.247244 \n",
       "C 62.734163 109.247244 67.060571 107.455187 70.250005 104.265753 \n",
       "C 73.439439 101.076319 75.231496 96.749911 75.231496 92.23937 \n",
       "C 75.231496 87.728829 73.439439 83.402421 70.250005 80.212987 \n",
       "C 67.060571 77.023553 62.734163 75.231496 58.223622 75.231496 \n",
       "C 53.713081 75.231496 49.386673 77.023553 46.197239 80.212987 \n",
       "C 43.007805 83.402421 41.215748 87.728829 41.215748 92.23937 \n",
       "C 41.215748 96.749911 43.007805 101.076319 46.197239 104.265753 \n",
       "C 49.386673 107.455187 53.713081 109.247244 58.223622 109.247244 \n",
       "L 58.223622 109.247244 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_8\">\n",
       "    <path clip-path=\"url(#pedb8c93ab8)\" d=\"M 58.223622 165.940157 \n",
       "C 62.734163 165.940157 67.060571 164.148101 70.250005 160.958667 \n",
       "C 73.439439 157.769232 75.231496 153.442824 75.231496 148.932283 \n",
       "C 75.231496 144.421743 73.439439 140.095334 70.250005 136.9059 \n",
       "C 67.060571 133.716466 62.734163 131.924409 58.223622 131.924409 \n",
       "C 53.713081 131.924409 49.386673 133.716466 46.197239 136.9059 \n",
       "C 43.007805 140.095334 41.215748 144.421743 41.215748 148.932283 \n",
       "C 41.215748 153.442824 43.007805 157.769232 46.197239 160.958667 \n",
       "C 49.386673 164.148101 53.713081 165.940157 58.223622 165.940157 \n",
       "L 58.223622 165.940157 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_9\">\n",
       "    <path clip-path=\"url(#pedb8c93ab8)\" d=\"M 126.255118 165.940157 \n",
       "C 130.765659 165.940157 135.092067 164.148101 138.281501 160.958667 \n",
       "C 141.470935 157.769232 143.262992 153.442824 143.262992 148.932283 \n",
       "C 143.262992 144.421743 141.470935 140.095334 138.281501 136.9059 \n",
       "C 135.092067 133.716466 130.765659 131.924409 126.255118 131.924409 \n",
       "C 121.744577 131.924409 117.418169 133.716466 114.228735 136.9059 \n",
       "C 111.039301 140.095334 109.247244 144.421743 109.247244 148.932283 \n",
       "C 109.247244 153.442824 111.039301 157.769232 114.228735 160.958667 \n",
       "C 117.418169 164.148101 121.744577 165.940157 126.255118 165.940157 \n",
       "L 126.255118 165.940157 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"matplotlib.axis_1\"/>\n",
       "   <g id=\"matplotlib.axis_2\"/>\n",
       "   <g id=\"text_1\">\n",
       "    <!-- students $s$ -->\n",
       "    <defs>\n",
       "     <path d=\"M 18.3125 70.21875 \n",
       "L 18.3125 54.6875 \n",
       "L 36.8125 54.6875 \n",
       "L 36.8125 47.703125 \n",
       "L 18.3125 47.703125 \n",
       "L 18.3125 18.015625 \n",
       "Q 18.3125 11.328125 20.140625 9.421875 \n",
       "Q 21.96875 7.515625 27.59375 7.515625 \n",
       "L 36.8125 7.515625 \n",
       "L 36.8125 0 \n",
       "L 27.59375 0 \n",
       "Q 17.1875 0 13.234375 3.875 \n",
       "Q 9.28125 7.765625 9.28125 18.015625 \n",
       "L 9.28125 47.703125 \n",
       "L 2.6875 47.703125 \n",
       "L 2.6875 54.6875 \n",
       "L 9.28125 54.6875 \n",
       "L 9.28125 70.21875 \n",
       "z\n",
       "\" id=\"BitstreamVeraSans-Roman-74\"/>\n",
       "     <path d=\"M 43.203125 41 \n",
       "L 41 32.09375 \n",
       "L 39.5 32.09375 \n",
       "Q 37.796875 36.5 35.296875 37.890625 \n",
       "Q 32.796875 39.296875 28.890625 39.296875 \n",
       "Q 25 39.296875 23.046875 37.140625 \n",
       "Q 21.09375 35 21.09375 33 \n",
       "Q 21.09375 31 22.796875 29.546875 \n",
       "Q 24.5 28.09375 27.796875 26.5 \n",
       "Q 33.796875 23.59375 36.140625 21.34375 \n",
       "Q 38.5 19.09375 38.5 15.796875 \n",
       "Q 38.5 9 32.890625 4 \n",
       "Q 27.296875 -1 18.59375 -1 \n",
       "Q 14.09375 -1 11.390625 0.296875 \n",
       "Q 8.703125 1.59375 6.09375 4.5 \n",
       "L 8.59375 14.796875 \n",
       "L 10.09375 14.796875 \n",
       "Q 11.90625 6.09375 21 6.09375 \n",
       "Q 24.40625 6.09375 27.296875 7.84375 \n",
       "Q 30.203125 9.59375 30.203125 12.796875 \n",
       "Q 30.203125 14.296875 28.59375 15.640625 \n",
       "Q 27 17 23.203125 18.90625 \n",
       "Q 17.703125 21.59375 15.25 24.25 \n",
       "Q 12.796875 26.90625 12.796875 30.296875 \n",
       "Q 12.796875 36.5 18 41.390625 \n",
       "Q 23.203125 46.296875 30.90625 46.296875 \n",
       "Q 39.59375 46.296875 43.203125 41 \n",
       "\" id=\"STIXGeneral-Italic-1d634\"/>\n",
       "     <path d=\"M 44.28125 53.078125 \n",
       "L 44.28125 44.578125 \n",
       "Q 40.484375 46.53125 36.375 47.5 \n",
       "Q 32.28125 48.484375 27.875 48.484375 \n",
       "Q 21.1875 48.484375 17.84375 46.4375 \n",
       "Q 14.5 44.390625 14.5 40.28125 \n",
       "Q 14.5 37.15625 16.890625 35.375 \n",
       "Q 19.28125 33.59375 26.515625 31.984375 \n",
       "L 29.59375 31.296875 \n",
       "Q 39.15625 29.25 43.1875 25.515625 \n",
       "Q 47.21875 21.78125 47.21875 15.09375 \n",
       "Q 47.21875 7.46875 41.1875 3.015625 \n",
       "Q 35.15625 -1.421875 24.609375 -1.421875 \n",
       "Q 20.21875 -1.421875 15.453125 -0.5625 \n",
       "Q 10.6875 0.296875 5.421875 2 \n",
       "L 5.421875 11.28125 \n",
       "Q 10.40625 8.6875 15.234375 7.390625 \n",
       "Q 20.0625 6.109375 24.8125 6.109375 \n",
       "Q 31.15625 6.109375 34.5625 8.28125 \n",
       "Q 37.984375 10.453125 37.984375 14.40625 \n",
       "Q 37.984375 18.0625 35.515625 20.015625 \n",
       "Q 33.0625 21.96875 24.703125 23.78125 \n",
       "L 21.578125 24.515625 \n",
       "Q 13.234375 26.265625 9.515625 29.90625 \n",
       "Q 5.8125 33.546875 5.8125 39.890625 \n",
       "Q 5.8125 47.609375 11.28125 51.796875 \n",
       "Q 16.75 56 26.8125 56 \n",
       "Q 31.78125 56 36.171875 55.265625 \n",
       "Q 40.578125 54.546875 44.28125 53.078125 \n",
       "\" id=\"BitstreamVeraSans-Roman-73\"/>\n",
       "     <path id=\"BitstreamVeraSans-Roman-20\"/>\n",
       "     <path d=\"M 54.890625 33.015625 \n",
       "L 54.890625 0 \n",
       "L 45.90625 0 \n",
       "L 45.90625 32.71875 \n",
       "Q 45.90625 40.484375 42.875 44.328125 \n",
       "Q 39.84375 48.1875 33.796875 48.1875 \n",
       "Q 26.515625 48.1875 22.3125 43.546875 \n",
       "Q 18.109375 38.921875 18.109375 30.90625 \n",
       "L 18.109375 0 \n",
       "L 9.078125 0 \n",
       "L 9.078125 54.6875 \n",
       "L 18.109375 54.6875 \n",
       "L 18.109375 46.1875 \n",
       "Q 21.34375 51.125 25.703125 53.5625 \n",
       "Q 30.078125 56 35.796875 56 \n",
       "Q 45.21875 56 50.046875 50.171875 \n",
       "Q 54.890625 44.34375 54.890625 33.015625 \n",
       "\" id=\"BitstreamVeraSans-Roman-6e\"/>\n",
       "     <path d=\"M 45.40625 46.390625 \n",
       "L 45.40625 75.984375 \n",
       "L 54.390625 75.984375 \n",
       "L 54.390625 0 \n",
       "L 45.40625 0 \n",
       "L 45.40625 8.203125 \n",
       "Q 42.578125 3.328125 38.25 0.953125 \n",
       "Q 33.9375 -1.421875 27.875 -1.421875 \n",
       "Q 17.96875 -1.421875 11.734375 6.484375 \n",
       "Q 5.515625 14.40625 5.515625 27.296875 \n",
       "Q 5.515625 40.1875 11.734375 48.09375 \n",
       "Q 17.96875 56 27.875 56 \n",
       "Q 33.9375 56 38.25 53.625 \n",
       "Q 42.578125 51.265625 45.40625 46.390625 \n",
       "M 14.796875 27.296875 \n",
       "Q 14.796875 17.390625 18.875 11.75 \n",
       "Q 22.953125 6.109375 30.078125 6.109375 \n",
       "Q 37.203125 6.109375 41.296875 11.75 \n",
       "Q 45.40625 17.390625 45.40625 27.296875 \n",
       "Q 45.40625 37.203125 41.296875 42.84375 \n",
       "Q 37.203125 48.484375 30.078125 48.484375 \n",
       "Q 22.953125 48.484375 18.875 42.84375 \n",
       "Q 14.796875 37.203125 14.796875 27.296875 \n",
       "\" id=\"BitstreamVeraSans-Roman-64\"/>\n",
       "     <path d=\"M 56.203125 29.59375 \n",
       "L 56.203125 25.203125 \n",
       "L 14.890625 25.203125 \n",
       "Q 15.484375 15.921875 20.484375 11.0625 \n",
       "Q 25.484375 6.203125 34.421875 6.203125 \n",
       "Q 39.59375 6.203125 44.453125 7.46875 \n",
       "Q 49.3125 8.734375 54.109375 11.28125 \n",
       "L 54.109375 2.78125 \n",
       "Q 49.265625 0.734375 44.1875 -0.34375 \n",
       "Q 39.109375 -1.421875 33.890625 -1.421875 \n",
       "Q 20.796875 -1.421875 13.15625 6.1875 \n",
       "Q 5.515625 13.8125 5.515625 26.8125 \n",
       "Q 5.515625 40.234375 12.765625 48.109375 \n",
       "Q 20.015625 56 32.328125 56 \n",
       "Q 43.359375 56 49.78125 48.890625 \n",
       "Q 56.203125 41.796875 56.203125 29.59375 \n",
       "M 47.21875 32.234375 \n",
       "Q 47.125 39.59375 43.09375 43.984375 \n",
       "Q 39.0625 48.390625 32.421875 48.390625 \n",
       "Q 24.90625 48.390625 20.390625 44.140625 \n",
       "Q 15.875 39.890625 15.1875 32.171875 \n",
       "z\n",
       "\" id=\"BitstreamVeraSans-Roman-65\"/>\n",
       "     <path d=\"M 8.5 21.578125 \n",
       "L 8.5 54.6875 \n",
       "L 17.484375 54.6875 \n",
       "L 17.484375 21.921875 \n",
       "Q 17.484375 14.15625 20.5 10.265625 \n",
       "Q 23.53125 6.390625 29.59375 6.390625 \n",
       "Q 36.859375 6.390625 41.078125 11.03125 \n",
       "Q 45.3125 15.671875 45.3125 23.6875 \n",
       "L 45.3125 54.6875 \n",
       "L 54.296875 54.6875 \n",
       "L 54.296875 0 \n",
       "L 45.3125 0 \n",
       "L 45.3125 8.40625 \n",
       "Q 42.046875 3.421875 37.71875 1 \n",
       "Q 33.40625 -1.421875 27.6875 -1.421875 \n",
       "Q 18.265625 -1.421875 13.375 4.4375 \n",
       "Q 8.5 10.296875 8.5 21.578125 \n",
       "\" id=\"BitstreamVeraSans-Roman-75\"/>\n",
       "    </defs>\n",
       "    <g transform=\"translate(97.2393700787 200.62519685)scale(0.18 -0.18)\">\n",
       "     <use transform=\"translate(0.0 0.015625)\" xlink:href=\"#BitstreamVeraSans-Roman-73\"/>\n",
       "     <use transform=\"translate(52.099609375 0.015625)\" xlink:href=\"#BitstreamVeraSans-Roman-74\"/>\n",
       "     <use transform=\"translate(91.30859375 0.015625)\" xlink:href=\"#BitstreamVeraSans-Roman-75\"/>\n",
       "     <use transform=\"translate(154.6875 0.015625)\" xlink:href=\"#BitstreamVeraSans-Roman-64\"/>\n",
       "     <use transform=\"translate(218.1640625 0.015625)\" xlink:href=\"#BitstreamVeraSans-Roman-65\"/>\n",
       "     <use transform=\"translate(279.6875 0.015625)\" xlink:href=\"#BitstreamVeraSans-Roman-6e\"/>\n",
       "     <use transform=\"translate(343.06640625 0.015625)\" xlink:href=\"#BitstreamVeraSans-Roman-74\"/>\n",
       "     <use transform=\"translate(382.275390625 0.015625)\" xlink:href=\"#BitstreamVeraSans-Roman-73\"/>\n",
       "     <use transform=\"translate(434.375 0.015625)\" xlink:href=\"#BitstreamVeraSans-Roman-20\"/>\n",
       "     <use transform=\"translate(466.162109375 0.015625)\" xlink:href=\"#STIXGeneral-Italic-1d634\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"text_2\">\n",
       "    <!-- intell. -->\n",
       "    <defs>\n",
       "     <path d=\"M 9.421875 54.6875 \n",
       "L 18.40625 54.6875 \n",
       "L 18.40625 0 \n",
       "L 9.421875 0 \n",
       "z\n",
       "M 9.421875 75.984375 \n",
       "L 18.40625 75.984375 \n",
       "L 18.40625 64.59375 \n",
       "L 9.421875 64.59375 \n",
       "z\n",
       "\" id=\"BitstreamVeraSans-Roman-69\"/>\n",
       "     <path d=\"M 9.421875 75.984375 \n",
       "L 18.40625 75.984375 \n",
       "L 18.40625 0 \n",
       "L 9.421875 0 \n",
       "z\n",
       "\" id=\"BitstreamVeraSans-Roman-6c\"/>\n",
       "     <path d=\"M 10.6875 12.40625 \n",
       "L 21 12.40625 \n",
       "L 21 0 \n",
       "L 10.6875 0 \n",
       "z\n",
       "\" id=\"BitstreamVeraSans-Roman-2e\"/>\n",
       "    </defs>\n",
       "    <g transform=\"translate(115.08574311 94.4468700787)scale(0.08 -0.08)\">\n",
       "     <use xlink:href=\"#BitstreamVeraSans-Roman-69\"/>\n",
       "     <use x=\"27.783203125\" xlink:href=\"#BitstreamVeraSans-Roman-6e\"/>\n",
       "     <use x=\"91.162109375\" xlink:href=\"#BitstreamVeraSans-Roman-74\"/>\n",
       "     <use x=\"130.37109375\" xlink:href=\"#BitstreamVeraSans-Roman-65\"/>\n",
       "     <use x=\"191.89453125\" xlink:href=\"#BitstreamVeraSans-Roman-6c\"/>\n",
       "     <use x=\"219.677734375\" xlink:href=\"#BitstreamVeraSans-Roman-6c\"/>\n",
       "     <use x=\"247.4609375\" xlink:href=\"#BitstreamVeraSans-Roman-2e\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"text_3\">\n",
       "    <!-- $\\theta_I$ -->\n",
       "    <defs>\n",
       "     <path d=\"M 51.09375 49 \n",
       "Q 51.09375 38 47.140625 26.5 \n",
       "Q 43.203125 15 36 7 \n",
       "Q 28.796875 -1 20.59375 -1 \n",
       "Q 13.40625 -1 9.953125 4.25 \n",
       "Q 6.5 9.5 6.5 18.40625 \n",
       "Q 6.5 24.59375 8.640625 32.84375 \n",
       "Q 10.796875 41.09375 14.546875 49.140625 \n",
       "Q 18.296875 57.203125 24.546875 62.75 \n",
       "Q 30.796875 68.296875 37.90625 68.296875 \n",
       "Q 44.703125 68.296875 47.890625 62.9375 \n",
       "Q 51.09375 57.59375 51.09375 49 \n",
       "M 17.296875 37.296875 \n",
       "L 41.90625 37.296875 \n",
       "Q 43.203125 43.5 43.203125 48.5 \n",
       "Q 43.203125 61.203125 36 61.203125 \n",
       "Q 30.5 61.203125 25.390625 54.09375 \n",
       "Q 20.296875 47 17.296875 37.296875 \n",
       "M 40.203125 30.203125 \n",
       "L 15.59375 30.203125 \n",
       "Q 14.40625 24.296875 14.40625 19.296875 \n",
       "Q 14.40625 6.09375 22.296875 6.09375 \n",
       "Q 27.796875 6.09375 32.4375 12.84375 \n",
       "Q 37.09375 19.59375 40.203125 30.203125 \n",
       "\" id=\"STIXNonUnicode-Italic-e1df\"/>\n",
       "     <path d=\"M 51.203125 66.203125 \n",
       "L 50.203125 58.796875 \n",
       "L 39.09375 58.796875 \n",
       "L 26.296875 7.40625 \n",
       "L 37.40625 7.40625 \n",
       "L 34.703125 0 \n",
       "L 5.90625 0 \n",
       "L 6.296875 7.40625 \n",
       "L 17.40625 7.40625 \n",
       "L 30.203125 58.796875 \n",
       "L 19.09375 58.796875 \n",
       "L 22.40625 66.203125 \n",
       "z\n",
       "\" id=\"STIXGeneral-Italic-1d610\"/>\n",
       "    </defs>\n",
       "    <g transform=\"translate(50.7536220472 97.2062450787)scale(0.18 -0.18)\">\n",
       "     <use transform=\"translate(0.0 0.703125)\" xlink:href=\"#STIXNonUnicode-Italic-e1df\"/>\n",
       "     <use transform=\"translate(52.59268310546875 -12.885937499999997)scale(0.7)\" xlink:href=\"#STIXGeneral-Italic-1d610\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"text_4\">\n",
       "    <!-- $\\theta_G$ -->\n",
       "    <defs>\n",
       "     <path d=\"M 75.5 56.5 \n",
       "L 73 46.203125 \n",
       "L 71.09375 46.203125 \n",
       "Q 67.90625 60 52.203125 60 \n",
       "Q 42.796875 60 35.046875 54.953125 \n",
       "Q 27.296875 49.90625 23.140625 42.203125 \n",
       "Q 19 34.5 19 26.203125 \n",
       "Q 19 17.5 24.203125 11.84375 \n",
       "Q 29.40625 6.203125 39.40625 6.203125 \n",
       "Q 47.703125 6.203125 52.046875 8 \n",
       "Q 56.40625 9.796875 57 12.296875 \n",
       "L 61 28.09375 \n",
       "L 52.09375 28.09375 \n",
       "L 52.09375 35.703125 \n",
       "L 71.59375 35.703125 \n",
       "L 64.09375 5.90625 \n",
       "Q 59.59375 3.296875 57.1875 2.1875 \n",
       "Q 54.796875 1.09375 49.34375 -0.15625 \n",
       "Q 43.90625 -1.40625 37.09375 -1.40625 \n",
       "Q 24.203125 -1.40625 16.953125 5.34375 \n",
       "Q 9.703125 12.09375 9.703125 23.40625 \n",
       "Q 9.703125 32.09375 13.34375 40.25 \n",
       "Q 17 48.40625 23.046875 54.40625 \n",
       "Q 29.09375 60.40625 37.296875 64 \n",
       "Q 45.5 67.59375 54.09375 67.59375 \n",
       "Q 70.59375 67.59375 75.5 56.5 \n",
       "\" id=\"STIXGeneral-Italic-1d60e\"/>\n",
       "    </defs>\n",
       "    <g transform=\"translate(48.8636220472 153.899158465)scale(0.18 -0.18)\">\n",
       "     <use transform=\"translate(0.0 0.703125)\" xlink:href=\"#STIXNonUnicode-Italic-e1df\"/>\n",
       "     <use transform=\"translate(52.59268310546875 -12.885937499999997)scale(0.7)\" xlink:href=\"#STIXGeneral-Italic-1d60e\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"text_5\">\n",
       "    <!-- grade -->\n",
       "    <defs>\n",
       "     <path d=\"M 45.40625 27.984375 \n",
       "Q 45.40625 37.75 41.375 43.109375 \n",
       "Q 37.359375 48.484375 30.078125 48.484375 \n",
       "Q 22.859375 48.484375 18.828125 43.109375 \n",
       "Q 14.796875 37.75 14.796875 27.984375 \n",
       "Q 14.796875 18.265625 18.828125 12.890625 \n",
       "Q 22.859375 7.515625 30.078125 7.515625 \n",
       "Q 37.359375 7.515625 41.375 12.890625 \n",
       "Q 45.40625 18.265625 45.40625 27.984375 \n",
       "M 54.390625 6.78125 \n",
       "Q 54.390625 -7.171875 48.1875 -13.984375 \n",
       "Q 42 -20.796875 29.203125 -20.796875 \n",
       "Q 24.46875 -20.796875 20.265625 -20.09375 \n",
       "Q 16.0625 -19.390625 12.109375 -17.921875 \n",
       "L 12.109375 -9.1875 \n",
       "Q 16.0625 -11.328125 19.921875 -12.34375 \n",
       "Q 23.78125 -13.375 27.78125 -13.375 \n",
       "Q 36.625 -13.375 41.015625 -8.765625 \n",
       "Q 45.40625 -4.15625 45.40625 5.171875 \n",
       "L 45.40625 9.625 \n",
       "Q 42.625 4.78125 38.28125 2.390625 \n",
       "Q 33.9375 0 27.875 0 \n",
       "Q 17.828125 0 11.671875 7.65625 \n",
       "Q 5.515625 15.328125 5.515625 27.984375 \n",
       "Q 5.515625 40.671875 11.671875 48.328125 \n",
       "Q 17.828125 56 27.875 56 \n",
       "Q 33.9375 56 38.28125 53.609375 \n",
       "Q 42.625 51.21875 45.40625 46.390625 \n",
       "L 45.40625 54.6875 \n",
       "L 54.390625 54.6875 \n",
       "z\n",
       "\" id=\"BitstreamVeraSans-Roman-67\"/>\n",
       "     <path d=\"M 34.28125 27.484375 \n",
       "Q 23.390625 27.484375 19.1875 25 \n",
       "Q 14.984375 22.515625 14.984375 16.5 \n",
       "Q 14.984375 11.71875 18.140625 8.90625 \n",
       "Q 21.296875 6.109375 26.703125 6.109375 \n",
       "Q 34.1875 6.109375 38.703125 11.40625 \n",
       "Q 43.21875 16.703125 43.21875 25.484375 \n",
       "L 43.21875 27.484375 \n",
       "z\n",
       "M 52.203125 31.203125 \n",
       "L 52.203125 0 \n",
       "L 43.21875 0 \n",
       "L 43.21875 8.296875 \n",
       "Q 40.140625 3.328125 35.546875 0.953125 \n",
       "Q 30.953125 -1.421875 24.3125 -1.421875 \n",
       "Q 15.921875 -1.421875 10.953125 3.296875 \n",
       "Q 6 8.015625 6 15.921875 \n",
       "Q 6 25.140625 12.171875 29.828125 \n",
       "Q 18.359375 34.515625 30.609375 34.515625 \n",
       "L 43.21875 34.515625 \n",
       "L 43.21875 35.40625 \n",
       "Q 43.21875 41.609375 39.140625 45 \n",
       "Q 35.0625 48.390625 27.6875 48.390625 \n",
       "Q 23 48.390625 18.546875 47.265625 \n",
       "Q 14.109375 46.140625 10.015625 43.890625 \n",
       "L 10.015625 52.203125 \n",
       "Q 14.9375 54.109375 19.578125 55.046875 \n",
       "Q 24.21875 56 28.609375 56 \n",
       "Q 40.484375 56 46.34375 49.84375 \n",
       "Q 52.203125 43.703125 52.203125 31.203125 \n",
       "\" id=\"BitstreamVeraSans-Roman-61\"/>\n",
       "     <path d=\"M 41.109375 46.296875 \n",
       "Q 39.59375 47.171875 37.8125 47.578125 \n",
       "Q 36.03125 48 33.890625 48 \n",
       "Q 26.265625 48 22.1875 43.046875 \n",
       "Q 18.109375 38.09375 18.109375 28.8125 \n",
       "L 18.109375 0 \n",
       "L 9.078125 0 \n",
       "L 9.078125 54.6875 \n",
       "L 18.109375 54.6875 \n",
       "L 18.109375 46.1875 \n",
       "Q 20.953125 51.171875 25.484375 53.578125 \n",
       "Q 30.03125 56 36.53125 56 \n",
       "Q 37.453125 56 38.578125 55.875 \n",
       "Q 39.703125 55.765625 41.0625 55.515625 \n",
       "z\n",
       "\" id=\"BitstreamVeraSans-Roman-72\"/>\n",
       "    </defs>\n",
       "    <g transform=\"translate(114.61949311 151.139783465)scale(0.08 -0.08)\">\n",
       "     <use xlink:href=\"#BitstreamVeraSans-Roman-67\"/>\n",
       "     <use x=\"63.4765625\" xlink:href=\"#BitstreamVeraSans-Roman-72\"/>\n",
       "     <use x=\"104.58984375\" xlink:href=\"#BitstreamVeraSans-Roman-61\"/>\n",
       "     <use x=\"165.869140625\" xlink:href=\"#BitstreamVeraSans-Roman-64\"/>\n",
       "     <use x=\"229.345703125\" xlink:href=\"#BitstreamVeraSans-Roman-65\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "  </g>\n",
       " </g>\n",
       " <defs>\n",
       "  <clipPath id=\"pedb8c93ab8\">\n",
       "   <rect height=\"226.771653543\" width=\"226.771653543\" x=\"7.2\" y=\"7.2\"/>\n",
       "  </clipPath>\n",
       " </defs>\n",
       "</svg>\n"
      ],
      "text/plain": [
       "<matplotlib.figure.Figure at 0x7feb96b18470>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "pgm = daft.PGM([4, 4], origin=[-0.5, 0.5])\n",
    "add_node(pgm, 'tI', r'$\\theta_I$', 0.4, 3)\n",
    "add_node(pgm, 'I', 'intell.', 1.6, 3, label_params={'size':8})\n",
    "add_node(pgm, 'tG', r'$\\theta_G$', 0.4, 2)\n",
    "add_node(pgm, 'G', 'grade', 1.6, 2, label_params={'size':8})\n",
    "add_edges(pgm, [\n",
    "        ('tI', 'I'),\n",
    "        ('tG', 'G'),\n",
    "        ('I', 'G')\n",
    "    ])\n",
    "pgm.add_plate(daft.Plate((1,1,2,2.5), label='students $s$'))\n",
    "pgm.render()\n",
    "save('bn_plate_model_02')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "image/svg+xml": [
       "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"no\"?>\n",
       "<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\n",
       "  \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n",
       "<!-- Created with matplotlib (http://matplotlib.org/) -->\n",
       "<svg height=\"269pt\" version=\"1.1\" viewBox=\"0 0 269 269\" width=\"269pt\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n",
       " <defs>\n",
       "  <style type=\"text/css\">\n",
       "*{stroke-linecap:butt;stroke-linejoin:round;stroke-miterlimit:100000;}\n",
       "  </style>\n",
       " </defs>\n",
       " <g id=\"figure_1\">\n",
       "  <g id=\"patch_1\">\n",
       "   <path d=\"M -0 269.51811 \n",
       "L 269.51811 269.51811 \n",
       "L 269.51811 -0 \n",
       "L -0 -0 \n",
       "L -0 269.51811 \n",
       "z\n",
       "\" style=\"fill:none;\"/>\n",
       "  </g>\n",
       "  <g id=\"axes_1\">\n",
       "   <g id=\"patch_2\">\n",
       "    <path clip-path=\"url(#pf67c68a5ee)\" d=\"M 92.23937 233.971654 \n",
       "L 205.625197 233.971654 \n",
       "L 205.625197 92.23937 \n",
       "L 92.23937 92.23937 \n",
       "L 92.23937 233.971654 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_3\">\n",
       "    <path clip-path=\"url(#pf67c68a5ee)\" d=\"M 63.892913 262.31811 \n",
       "L 233.971654 262.31811 \n",
       "L 233.971654 35.546457 \n",
       "L 63.892913 35.546457 \n",
       "L 63.892913 262.31811 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_4\">\n",
       "    <path clip-path=\"url(#pf67c68a5ee)\" d=\"M 126.255118 160.270866 \n",
       "L 124.129134 157.43622 \n",
       "L 126.255118 157.43622 \n",
       "L 126.255118 137.593701 \n",
       "L 126.255118 137.593701 \n",
       "L 126.255118 157.43622 \n",
       "L 128.381102 157.43622 \n",
       "L 126.255118 160.270866 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_5\">\n",
       "    <path clip-path=\"url(#pf67c68a5ee)\" d=\"M 126.255118 103.577953 \n",
       "L 124.129134 100.743307 \n",
       "L 126.255118 100.743307 \n",
       "L 126.255118 80.900787 \n",
       "L 126.255118 80.900787 \n",
       "L 126.255118 100.743307 \n",
       "L 128.381102 100.743307 \n",
       "L 126.255118 103.577953 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_6\">\n",
       "    <path clip-path=\"url(#pf67c68a5ee)\" d=\"M 126.255118 137.593701 \n",
       "C 130.765659 137.593701 135.092067 135.801644 138.281501 132.61221 \n",
       "C 141.470935 129.422776 143.262992 125.096368 143.262992 120.585827 \n",
       "C 143.262992 116.075286 141.470935 111.748878 138.281501 108.559444 \n",
       "C 135.092067 105.37001 130.765659 103.577953 126.255118 103.577953 \n",
       "C 121.744577 103.577953 117.418169 105.37001 114.228735 108.559444 \n",
       "C 111.039301 111.748878 109.247244 116.075286 109.247244 120.585827 \n",
       "C 109.247244 125.096368 111.039301 129.422776 114.228735 132.61221 \n",
       "C 117.418169 135.801644 121.744577 137.593701 126.255118 137.593701 \n",
       "L 126.255118 137.593701 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_7\">\n",
       "    <path clip-path=\"url(#pf67c68a5ee)\" d=\"M 126.255118 80.900787 \n",
       "C 130.765659 80.900787 135.092067 79.108731 138.281501 75.919296 \n",
       "C 141.470935 72.729862 143.262992 68.403454 143.262992 63.892913 \n",
       "C 143.262992 59.382372 141.470935 55.055964 138.281501 51.86653 \n",
       "C 135.092067 48.677096 130.765659 46.885039 126.255118 46.885039 \n",
       "C 121.744577 46.885039 117.418169 48.677096 114.228735 51.86653 \n",
       "C 111.039301 55.055964 109.247244 59.382372 109.247244 63.892913 \n",
       "C 109.247244 68.403454 111.039301 72.729862 114.228735 75.919296 \n",
       "C 117.418169 79.108731 121.744577 80.900787 126.255118 80.900787 \n",
       "L 126.255118 80.900787 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_8\">\n",
       "    <path clip-path=\"url(#pf67c68a5ee)\" d=\"M 126.255118 194.286614 \n",
       "C 130.765659 194.286614 135.092067 192.494557 138.281501 189.305123 \n",
       "C 141.470935 186.115689 143.262992 181.789281 143.262992 177.27874 \n",
       "C 143.262992 172.768199 141.470935 168.441791 138.281501 165.252357 \n",
       "C 135.092067 162.062923 130.765659 160.270866 126.255118 160.270866 \n",
       "C 121.744577 160.270866 117.418169 162.062923 114.228735 165.252357 \n",
       "C 111.039301 168.441791 109.247244 172.768199 109.247244 177.27874 \n",
       "C 109.247244 181.789281 111.039301 186.115689 114.228735 189.305123 \n",
       "C 117.418169 192.494557 121.744577 194.286614 126.255118 194.286614 \n",
       "L 126.255118 194.286614 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"matplotlib.axis_1\"/>\n",
       "   <g id=\"matplotlib.axis_2\"/>\n",
       "   <g id=\"text_1\">\n",
       "    <!-- students $s$ -->\n",
       "    <defs>\n",
       "     <path d=\"M 18.3125 70.21875 \n",
       "L 18.3125 54.6875 \n",
       "L 36.8125 54.6875 \n",
       "L 36.8125 47.703125 \n",
       "L 18.3125 47.703125 \n",
       "L 18.3125 18.015625 \n",
       "Q 18.3125 11.328125 20.140625 9.421875 \n",
       "Q 21.96875 7.515625 27.59375 7.515625 \n",
       "L 36.8125 7.515625 \n",
       "L 36.8125 0 \n",
       "L 27.59375 0 \n",
       "Q 17.1875 0 13.234375 3.875 \n",
       "Q 9.28125 7.765625 9.28125 18.015625 \n",
       "L 9.28125 47.703125 \n",
       "L 2.6875 47.703125 \n",
       "L 2.6875 54.6875 \n",
       "L 9.28125 54.6875 \n",
       "L 9.28125 70.21875 \n",
       "z\n",
       "\" id=\"BitstreamVeraSans-Roman-74\"/>\n",
       "     <path d=\"M 43.203125 41 \n",
       "L 41 32.09375 \n",
       "L 39.5 32.09375 \n",
       "Q 37.796875 36.5 35.296875 37.890625 \n",
       "Q 32.796875 39.296875 28.890625 39.296875 \n",
       "Q 25 39.296875 23.046875 37.140625 \n",
       "Q 21.09375 35 21.09375 33 \n",
       "Q 21.09375 31 22.796875 29.546875 \n",
       "Q 24.5 28.09375 27.796875 26.5 \n",
       "Q 33.796875 23.59375 36.140625 21.34375 \n",
       "Q 38.5 19.09375 38.5 15.796875 \n",
       "Q 38.5 9 32.890625 4 \n",
       "Q 27.296875 -1 18.59375 -1 \n",
       "Q 14.09375 -1 11.390625 0.296875 \n",
       "Q 8.703125 1.59375 6.09375 4.5 \n",
       "L 8.59375 14.796875 \n",
       "L 10.09375 14.796875 \n",
       "Q 11.90625 6.09375 21 6.09375 \n",
       "Q 24.40625 6.09375 27.296875 7.84375 \n",
       "Q 30.203125 9.59375 30.203125 12.796875 \n",
       "Q 30.203125 14.296875 28.59375 15.640625 \n",
       "Q 27 17 23.203125 18.90625 \n",
       "Q 17.703125 21.59375 15.25 24.25 \n",
       "Q 12.796875 26.90625 12.796875 30.296875 \n",
       "Q 12.796875 36.5 18 41.390625 \n",
       "Q 23.203125 46.296875 30.90625 46.296875 \n",
       "Q 39.59375 46.296875 43.203125 41 \n",
       "\" id=\"STIXGeneral-Italic-1d634\"/>\n",
       "     <path d=\"M 44.28125 53.078125 \n",
       "L 44.28125 44.578125 \n",
       "Q 40.484375 46.53125 36.375 47.5 \n",
       "Q 32.28125 48.484375 27.875 48.484375 \n",
       "Q 21.1875 48.484375 17.84375 46.4375 \n",
       "Q 14.5 44.390625 14.5 40.28125 \n",
       "Q 14.5 37.15625 16.890625 35.375 \n",
       "Q 19.28125 33.59375 26.515625 31.984375 \n",
       "L 29.59375 31.296875 \n",
       "Q 39.15625 29.25 43.1875 25.515625 \n",
       "Q 47.21875 21.78125 47.21875 15.09375 \n",
       "Q 47.21875 7.46875 41.1875 3.015625 \n",
       "Q 35.15625 -1.421875 24.609375 -1.421875 \n",
       "Q 20.21875 -1.421875 15.453125 -0.5625 \n",
       "Q 10.6875 0.296875 5.421875 2 \n",
       "L 5.421875 11.28125 \n",
       "Q 10.40625 8.6875 15.234375 7.390625 \n",
       "Q 20.0625 6.109375 24.8125 6.109375 \n",
       "Q 31.15625 6.109375 34.5625 8.28125 \n",
       "Q 37.984375 10.453125 37.984375 14.40625 \n",
       "Q 37.984375 18.0625 35.515625 20.015625 \n",
       "Q 33.0625 21.96875 24.703125 23.78125 \n",
       "L 21.578125 24.515625 \n",
       "Q 13.234375 26.265625 9.515625 29.90625 \n",
       "Q 5.8125 33.546875 5.8125 39.890625 \n",
       "Q 5.8125 47.609375 11.28125 51.796875 \n",
       "Q 16.75 56 26.8125 56 \n",
       "Q 31.78125 56 36.171875 55.265625 \n",
       "Q 40.578125 54.546875 44.28125 53.078125 \n",
       "\" id=\"BitstreamVeraSans-Roman-73\"/>\n",
       "     <path id=\"BitstreamVeraSans-Roman-20\"/>\n",
       "     <path d=\"M 54.890625 33.015625 \n",
       "L 54.890625 0 \n",
       "L 45.90625 0 \n",
       "L 45.90625 32.71875 \n",
       "Q 45.90625 40.484375 42.875 44.328125 \n",
       "Q 39.84375 48.1875 33.796875 48.1875 \n",
       "Q 26.515625 48.1875 22.3125 43.546875 \n",
       "Q 18.109375 38.921875 18.109375 30.90625 \n",
       "L 18.109375 0 \n",
       "L 9.078125 0 \n",
       "L 9.078125 54.6875 \n",
       "L 18.109375 54.6875 \n",
       "L 18.109375 46.1875 \n",
       "Q 21.34375 51.125 25.703125 53.5625 \n",
       "Q 30.078125 56 35.796875 56 \n",
       "Q 45.21875 56 50.046875 50.171875 \n",
       "Q 54.890625 44.34375 54.890625 33.015625 \n",
       "\" id=\"BitstreamVeraSans-Roman-6e\"/>\n",
       "     <path d=\"M 45.40625 46.390625 \n",
       "L 45.40625 75.984375 \n",
       "L 54.390625 75.984375 \n",
       "L 54.390625 0 \n",
       "L 45.40625 0 \n",
       "L 45.40625 8.203125 \n",
       "Q 42.578125 3.328125 38.25 0.953125 \n",
       "Q 33.9375 -1.421875 27.875 -1.421875 \n",
       "Q 17.96875 -1.421875 11.734375 6.484375 \n",
       "Q 5.515625 14.40625 5.515625 27.296875 \n",
       "Q 5.515625 40.1875 11.734375 48.09375 \n",
       "Q 17.96875 56 27.875 56 \n",
       "Q 33.9375 56 38.25 53.625 \n",
       "Q 42.578125 51.265625 45.40625 46.390625 \n",
       "M 14.796875 27.296875 \n",
       "Q 14.796875 17.390625 18.875 11.75 \n",
       "Q 22.953125 6.109375 30.078125 6.109375 \n",
       "Q 37.203125 6.109375 41.296875 11.75 \n",
       "Q 45.40625 17.390625 45.40625 27.296875 \n",
       "Q 45.40625 37.203125 41.296875 42.84375 \n",
       "Q 37.203125 48.484375 30.078125 48.484375 \n",
       "Q 22.953125 48.484375 18.875 42.84375 \n",
       "Q 14.796875 37.203125 14.796875 27.296875 \n",
       "\" id=\"BitstreamVeraSans-Roman-64\"/>\n",
       "     <path d=\"M 56.203125 29.59375 \n",
       "L 56.203125 25.203125 \n",
       "L 14.890625 25.203125 \n",
       "Q 15.484375 15.921875 20.484375 11.0625 \n",
       "Q 25.484375 6.203125 34.421875 6.203125 \n",
       "Q 39.59375 6.203125 44.453125 7.46875 \n",
       "Q 49.3125 8.734375 54.109375 11.28125 \n",
       "L 54.109375 2.78125 \n",
       "Q 49.265625 0.734375 44.1875 -0.34375 \n",
       "Q 39.109375 -1.421875 33.890625 -1.421875 \n",
       "Q 20.796875 -1.421875 13.15625 6.1875 \n",
       "Q 5.515625 13.8125 5.515625 26.8125 \n",
       "Q 5.515625 40.234375 12.765625 48.109375 \n",
       "Q 20.015625 56 32.328125 56 \n",
       "Q 43.359375 56 49.78125 48.890625 \n",
       "Q 56.203125 41.796875 56.203125 29.59375 \n",
       "M 47.21875 32.234375 \n",
       "Q 47.125 39.59375 43.09375 43.984375 \n",
       "Q 39.0625 48.390625 32.421875 48.390625 \n",
       "Q 24.90625 48.390625 20.390625 44.140625 \n",
       "Q 15.875 39.890625 15.1875 32.171875 \n",
       "z\n",
       "\" id=\"BitstreamVeraSans-Roman-65\"/>\n",
       "     <path d=\"M 8.5 21.578125 \n",
       "L 8.5 54.6875 \n",
       "L 17.484375 54.6875 \n",
       "L 17.484375 21.921875 \n",
       "Q 17.484375 14.15625 20.5 10.265625 \n",
       "Q 23.53125 6.390625 29.59375 6.390625 \n",
       "Q 36.859375 6.390625 41.078125 11.03125 \n",
       "Q 45.3125 15.671875 45.3125 23.6875 \n",
       "L 45.3125 54.6875 \n",
       "L 54.296875 54.6875 \n",
       "L 54.296875 0 \n",
       "L 45.3125 0 \n",
       "L 45.3125 8.40625 \n",
       "Q 42.046875 3.421875 37.71875 1 \n",
       "Q 33.40625 -1.421875 27.6875 -1.421875 \n",
       "Q 18.265625 -1.421875 13.375 4.4375 \n",
       "Q 8.5 10.296875 8.5 21.578125 \n",
       "\" id=\"BitstreamVeraSans-Roman-75\"/>\n",
       "    </defs>\n",
       "    <g transform=\"translate(97.2393700787 228.971653543)scale(0.18 -0.18)\">\n",
       "     <use transform=\"translate(0.0 0.015625)\" xlink:href=\"#BitstreamVeraSans-Roman-73\"/>\n",
       "     <use transform=\"translate(52.099609375 0.015625)\" xlink:href=\"#BitstreamVeraSans-Roman-74\"/>\n",
       "     <use transform=\"translate(91.30859375 0.015625)\" xlink:href=\"#BitstreamVeraSans-Roman-75\"/>\n",
       "     <use transform=\"translate(154.6875 0.015625)\" xlink:href=\"#BitstreamVeraSans-Roman-64\"/>\n",
       "     <use transform=\"translate(218.1640625 0.015625)\" xlink:href=\"#BitstreamVeraSans-Roman-65\"/>\n",
       "     <use transform=\"translate(279.6875 0.015625)\" xlink:href=\"#BitstreamVeraSans-Roman-6e\"/>\n",
       "     <use transform=\"translate(343.06640625 0.015625)\" xlink:href=\"#BitstreamVeraSans-Roman-74\"/>\n",
       "     <use transform=\"translate(382.275390625 0.015625)\" xlink:href=\"#BitstreamVeraSans-Roman-73\"/>\n",
       "     <use transform=\"translate(434.375 0.015625)\" xlink:href=\"#BitstreamVeraSans-Roman-20\"/>\n",
       "     <use transform=\"translate(466.162109375 0.015625)\" xlink:href=\"#STIXGeneral-Italic-1d634\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"text_2\">\n",
       "    <!-- courses $c$ -->\n",
       "    <defs>\n",
       "     <path d=\"M 48.78125 52.59375 \n",
       "L 48.78125 44.1875 \n",
       "Q 44.96875 46.296875 41.140625 47.34375 \n",
       "Q 37.3125 48.390625 33.40625 48.390625 \n",
       "Q 24.65625 48.390625 19.8125 42.84375 \n",
       "Q 14.984375 37.3125 14.984375 27.296875 \n",
       "Q 14.984375 17.28125 19.8125 11.734375 \n",
       "Q 24.65625 6.203125 33.40625 6.203125 \n",
       "Q 37.3125 6.203125 41.140625 7.25 \n",
       "Q 44.96875 8.296875 48.78125 10.40625 \n",
       "L 48.78125 2.09375 \n",
       "Q 45.015625 0.34375 40.984375 -0.53125 \n",
       "Q 36.96875 -1.421875 32.421875 -1.421875 \n",
       "Q 20.0625 -1.421875 12.78125 6.34375 \n",
       "Q 5.515625 14.109375 5.515625 27.296875 \n",
       "Q 5.515625 40.671875 12.859375 48.328125 \n",
       "Q 20.21875 56 33.015625 56 \n",
       "Q 37.15625 56 41.109375 55.140625 \n",
       "Q 45.0625 54.296875 48.78125 52.59375 \n",
       "\" id=\"BitstreamVeraSans-Roman-63\"/>\n",
       "     <path d=\"M 50.296875 37.09375 \n",
       "L 44.59375 31.703125 \n",
       "L 43 31.703125 \n",
       "Q 41.59375 39.203125 33.5 39.203125 \n",
       "Q 27.09375 39.203125 21.046875 33.09375 \n",
       "Q 15 27 15 16.90625 \n",
       "Q 15 11.796875 17.84375 8.9375 \n",
       "Q 20.703125 6.09375 25.296875 6.09375 \n",
       "Q 33.40625 6.09375 40.796875 16.59375 \n",
       "L 46.40625 13.203125 \n",
       "Q 36.796875 -1 22.90625 -1 \n",
       "Q 15.5 -1 11.09375 3.203125 \n",
       "Q 6.703125 7.40625 6.703125 15 \n",
       "Q 6.703125 28 15.890625 37.140625 \n",
       "Q 25.09375 46.296875 35.703125 46.296875 \n",
       "Q 41.203125 46.296875 45.140625 44 \n",
       "Q 49.09375 41.703125 50.296875 37.09375 \n",
       "\" id=\"STIXGeneral-Italic-1d624\"/>\n",
       "     <path d=\"M 41.109375 46.296875 \n",
       "Q 39.59375 47.171875 37.8125 47.578125 \n",
       "Q 36.03125 48 33.890625 48 \n",
       "Q 26.265625 48 22.1875 43.046875 \n",
       "Q 18.109375 38.09375 18.109375 28.8125 \n",
       "L 18.109375 0 \n",
       "L 9.078125 0 \n",
       "L 9.078125 54.6875 \n",
       "L 18.109375 54.6875 \n",
       "L 18.109375 46.1875 \n",
       "Q 20.953125 51.171875 25.484375 53.578125 \n",
       "Q 30.03125 56 36.53125 56 \n",
       "Q 37.453125 56 38.578125 55.875 \n",
       "Q 39.703125 55.765625 41.0625 55.515625 \n",
       "z\n",
       "\" id=\"BitstreamVeraSans-Roman-72\"/>\n",
       "     <path d=\"M 30.609375 48.390625 \n",
       "Q 23.390625 48.390625 19.1875 42.75 \n",
       "Q 14.984375 37.109375 14.984375 27.296875 \n",
       "Q 14.984375 17.484375 19.15625 11.84375 \n",
       "Q 23.34375 6.203125 30.609375 6.203125 \n",
       "Q 37.796875 6.203125 41.984375 11.859375 \n",
       "Q 46.1875 17.53125 46.1875 27.296875 \n",
       "Q 46.1875 37.015625 41.984375 42.703125 \n",
       "Q 37.796875 48.390625 30.609375 48.390625 \n",
       "M 30.609375 56 \n",
       "Q 42.328125 56 49.015625 48.375 \n",
       "Q 55.71875 40.765625 55.71875 27.296875 \n",
       "Q 55.71875 13.875 49.015625 6.21875 \n",
       "Q 42.328125 -1.421875 30.609375 -1.421875 \n",
       "Q 18.84375 -1.421875 12.171875 6.21875 \n",
       "Q 5.515625 13.875 5.515625 27.296875 \n",
       "Q 5.515625 40.765625 12.171875 48.375 \n",
       "Q 18.84375 56 30.609375 56 \n",
       "\" id=\"BitstreamVeraSans-Roman-6f\"/>\n",
       "    </defs>\n",
       "    <g transform=\"translate(68.8929133858 257.318110236)scale(0.18 -0.18)\">\n",
       "     <use xlink:href=\"#BitstreamVeraSans-Roman-63\"/>\n",
       "     <use transform=\"translate(54.98046875 0.0)\" xlink:href=\"#BitstreamVeraSans-Roman-6f\"/>\n",
       "     <use transform=\"translate(116.162109375 0.0)\" xlink:href=\"#BitstreamVeraSans-Roman-75\"/>\n",
       "     <use transform=\"translate(179.541015625 0.0)\" xlink:href=\"#BitstreamVeraSans-Roman-72\"/>\n",
       "     <use transform=\"translate(220.654296875 0.0)\" xlink:href=\"#BitstreamVeraSans-Roman-73\"/>\n",
       "     <use transform=\"translate(272.75390625 0.0)\" xlink:href=\"#BitstreamVeraSans-Roman-65\"/>\n",
       "     <use transform=\"translate(334.27734375 0.0)\" xlink:href=\"#BitstreamVeraSans-Roman-73\"/>\n",
       "     <use transform=\"translate(386.376953125 0.0)\" xlink:href=\"#BitstreamVeraSans-Roman-20\"/>\n",
       "     <use transform=\"translate(418.1640625 0.0)\" xlink:href=\"#STIXGeneral-Italic-1d624\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"text_3\">\n",
       "    <!-- intell. -->\n",
       "    <defs>\n",
       "     <path d=\"M 9.421875 54.6875 \n",
       "L 18.40625 54.6875 \n",
       "L 18.40625 0 \n",
       "L 9.421875 0 \n",
       "z\n",
       "M 9.421875 75.984375 \n",
       "L 18.40625 75.984375 \n",
       "L 18.40625 64.59375 \n",
       "L 9.421875 64.59375 \n",
       "z\n",
       "\" id=\"BitstreamVeraSans-Roman-69\"/>\n",
       "     <path d=\"M 9.421875 75.984375 \n",
       "L 18.40625 75.984375 \n",
       "L 18.40625 0 \n",
       "L 9.421875 0 \n",
       "z\n",
       "\" id=\"BitstreamVeraSans-Roman-6c\"/>\n",
       "     <path d=\"M 10.6875 12.40625 \n",
       "L 21 12.40625 \n",
       "L 21 0 \n",
       "L 10.6875 0 \n",
       "z\n",
       "\" id=\"BitstreamVeraSans-Roman-2e\"/>\n",
       "    </defs>\n",
       "    <g transform=\"translate(115.08574311 122.793326772)scale(0.08 -0.08)\">\n",
       "     <use xlink:href=\"#BitstreamVeraSans-Roman-69\"/>\n",
       "     <use x=\"27.783203125\" xlink:href=\"#BitstreamVeraSans-Roman-6e\"/>\n",
       "     <use x=\"91.162109375\" xlink:href=\"#BitstreamVeraSans-Roman-74\"/>\n",
       "     <use x=\"130.37109375\" xlink:href=\"#BitstreamVeraSans-Roman-65\"/>\n",
       "     <use x=\"191.89453125\" xlink:href=\"#BitstreamVeraSans-Roman-6c\"/>\n",
       "     <use x=\"219.677734375\" xlink:href=\"#BitstreamVeraSans-Roman-6c\"/>\n",
       "     <use x=\"247.4609375\" xlink:href=\"#BitstreamVeraSans-Roman-2e\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"text_4\">\n",
       "    <!-- diffic. -->\n",
       "    <defs>\n",
       "     <path d=\"M 37.109375 75.984375 \n",
       "L 37.109375 68.5 \n",
       "L 28.515625 68.5 \n",
       "Q 23.6875 68.5 21.796875 66.546875 \n",
       "Q 19.921875 64.59375 19.921875 59.515625 \n",
       "L 19.921875 54.6875 \n",
       "L 34.71875 54.6875 \n",
       "L 34.71875 47.703125 \n",
       "L 19.921875 47.703125 \n",
       "L 19.921875 0 \n",
       "L 10.890625 0 \n",
       "L 10.890625 47.703125 \n",
       "L 2.296875 47.703125 \n",
       "L 2.296875 54.6875 \n",
       "L 10.890625 54.6875 \n",
       "L 10.890625 58.5 \n",
       "Q 10.890625 67.625 15.140625 71.796875 \n",
       "Q 19.390625 75.984375 28.609375 75.984375 \n",
       "z\n",
       "\" id=\"BitstreamVeraSans-Roman-66\"/>\n",
       "    </defs>\n",
       "    <g transform=\"translate(115.20636811 66.1004133858)scale(0.08 -0.08)\">\n",
       "     <use xlink:href=\"#BitstreamVeraSans-Roman-64\"/>\n",
       "     <use x=\"63.4765625\" xlink:href=\"#BitstreamVeraSans-Roman-69\"/>\n",
       "     <use x=\"91.259765625\" xlink:href=\"#BitstreamVeraSans-Roman-66\"/>\n",
       "     <use x=\"126.46484375\" xlink:href=\"#BitstreamVeraSans-Roman-66\"/>\n",
       "     <use x=\"161.669921875\" xlink:href=\"#BitstreamVeraSans-Roman-69\"/>\n",
       "     <use x=\"189.453125\" xlink:href=\"#BitstreamVeraSans-Roman-63\"/>\n",
       "     <use x=\"244.43359375\" xlink:href=\"#BitstreamVeraSans-Roman-2e\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"text_5\">\n",
       "    <!-- grade -->\n",
       "    <defs>\n",
       "     <path d=\"M 45.40625 27.984375 \n",
       "Q 45.40625 37.75 41.375 43.109375 \n",
       "Q 37.359375 48.484375 30.078125 48.484375 \n",
       "Q 22.859375 48.484375 18.828125 43.109375 \n",
       "Q 14.796875 37.75 14.796875 27.984375 \n",
       "Q 14.796875 18.265625 18.828125 12.890625 \n",
       "Q 22.859375 7.515625 30.078125 7.515625 \n",
       "Q 37.359375 7.515625 41.375 12.890625 \n",
       "Q 45.40625 18.265625 45.40625 27.984375 \n",
       "M 54.390625 6.78125 \n",
       "Q 54.390625 -7.171875 48.1875 -13.984375 \n",
       "Q 42 -20.796875 29.203125 -20.796875 \n",
       "Q 24.46875 -20.796875 20.265625 -20.09375 \n",
       "Q 16.0625 -19.390625 12.109375 -17.921875 \n",
       "L 12.109375 -9.1875 \n",
       "Q 16.0625 -11.328125 19.921875 -12.34375 \n",
       "Q 23.78125 -13.375 27.78125 -13.375 \n",
       "Q 36.625 -13.375 41.015625 -8.765625 \n",
       "Q 45.40625 -4.15625 45.40625 5.171875 \n",
       "L 45.40625 9.625 \n",
       "Q 42.625 4.78125 38.28125 2.390625 \n",
       "Q 33.9375 0 27.875 0 \n",
       "Q 17.828125 0 11.671875 7.65625 \n",
       "Q 5.515625 15.328125 5.515625 27.984375 \n",
       "Q 5.515625 40.671875 11.671875 48.328125 \n",
       "Q 17.828125 56 27.875 56 \n",
       "Q 33.9375 56 38.28125 53.609375 \n",
       "Q 42.625 51.21875 45.40625 46.390625 \n",
       "L 45.40625 54.6875 \n",
       "L 54.390625 54.6875 \n",
       "z\n",
       "\" id=\"BitstreamVeraSans-Roman-67\"/>\n",
       "     <path d=\"M 34.28125 27.484375 \n",
       "Q 23.390625 27.484375 19.1875 25 \n",
       "Q 14.984375 22.515625 14.984375 16.5 \n",
       "Q 14.984375 11.71875 18.140625 8.90625 \n",
       "Q 21.296875 6.109375 26.703125 6.109375 \n",
       "Q 34.1875 6.109375 38.703125 11.40625 \n",
       "Q 43.21875 16.703125 43.21875 25.484375 \n",
       "L 43.21875 27.484375 \n",
       "z\n",
       "M 52.203125 31.203125 \n",
       "L 52.203125 0 \n",
       "L 43.21875 0 \n",
       "L 43.21875 8.296875 \n",
       "Q 40.140625 3.328125 35.546875 0.953125 \n",
       "Q 30.953125 -1.421875 24.3125 -1.421875 \n",
       "Q 15.921875 -1.421875 10.953125 3.296875 \n",
       "Q 6 8.015625 6 15.921875 \n",
       "Q 6 25.140625 12.171875 29.828125 \n",
       "Q 18.359375 34.515625 30.609375 34.515625 \n",
       "L 43.21875 34.515625 \n",
       "L 43.21875 35.40625 \n",
       "Q 43.21875 41.609375 39.140625 45 \n",
       "Q 35.0625 48.390625 27.6875 48.390625 \n",
       "Q 23 48.390625 18.546875 47.265625 \n",
       "Q 14.109375 46.140625 10.015625 43.890625 \n",
       "L 10.015625 52.203125 \n",
       "Q 14.9375 54.109375 19.578125 55.046875 \n",
       "Q 24.21875 56 28.609375 56 \n",
       "Q 40.484375 56 46.34375 49.84375 \n",
       "Q 52.203125 43.703125 52.203125 31.203125 \n",
       "\" id=\"BitstreamVeraSans-Roman-61\"/>\n",
       "    </defs>\n",
       "    <g transform=\"translate(114.61949311 179.486240157)scale(0.08 -0.08)\">\n",
       "     <use xlink:href=\"#BitstreamVeraSans-Roman-67\"/>\n",
       "     <use x=\"63.4765625\" xlink:href=\"#BitstreamVeraSans-Roman-72\"/>\n",
       "     <use x=\"104.58984375\" xlink:href=\"#BitstreamVeraSans-Roman-61\"/>\n",
       "     <use x=\"165.869140625\" xlink:href=\"#BitstreamVeraSans-Roman-64\"/>\n",
       "     <use x=\"229.345703125\" xlink:href=\"#BitstreamVeraSans-Roman-65\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "  </g>\n",
       " </g>\n",
       " <defs>\n",
       "  <clipPath id=\"pf67c68a5ee\">\n",
       "   <rect height=\"255.118110236\" width=\"255.118110236\" x=\"7.2\" y=\"7.2\"/>\n",
       "  </clipPath>\n",
       " </defs>\n",
       "</svg>\n"
      ],
      "text/plain": [
       "<matplotlib.figure.Figure at 0x7feb96b18748>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "pgm = daft.PGM([4.5, 4.5], origin=[-0.5, 0.5])\n",
    "add_node(pgm, 'I', 'intell.', 1.6, 3, label_params={'size':8})\n",
    "add_node(pgm, 'D', 'diffic.', 1.6, 4, label_params={'size':8})\n",
    "add_node(pgm, 'G', 'grade', 1.6, 2, label_params={'size':8})\n",
    "add_edges(pgm, [\n",
    "        ('I', 'G'),\n",
    "        ('D', 'I')\n",
    "    ])\n",
    "pgm.add_plate(daft.Plate((1,1,2,2.5), label='students $s$'))\n",
    "pgm.add_plate(daft.Plate((0.5,0.5,3,4), label='courses $c$'))\n",
    "pgm.render()\n",
    "save('bn_plate_model_02_nested')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "image/svg+xml": [
       "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"no\"?>\n",
       "<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\n",
       "  \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n",
       "<!-- Created with matplotlib (http://matplotlib.org/) -->\n",
       "<svg height=\"184pt\" version=\"1.1\" viewBox=\"0 0 354 184\" width=\"354pt\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n",
       " <defs>\n",
       "  <style type=\"text/css\">\n",
       "*{stroke-linecap:butt;stroke-linejoin:round;stroke-miterlimit:100000;}\n",
       "  </style>\n",
       " </defs>\n",
       " <g id=\"figure_1\">\n",
       "  <g id=\"patch_1\">\n",
       "   <path d=\"M 0 184.47874 \n",
       "L 354.55748 184.47874 \n",
       "L 354.55748 0 \n",
       "L 0 0 \n",
       "L 0 184.47874 \n",
       "z\n",
       "\" style=\"fill:none;\"/>\n",
       "  </g>\n",
       "  <g id=\"axes_1\">\n",
       "   <g id=\"patch_2\">\n",
       "    <path clip-path=\"url(#p9532acebed)\" d=\"M 63.892913 177.27874 \n",
       "L 233.971654 177.27874 \n",
       "L 233.971654 35.546457 \n",
       "L 63.892913 35.546457 \n",
       "L 63.892913 177.27874 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_3\">\n",
       "    <path clip-path=\"url(#p9532acebed)\" d=\"M 177.27874 171.609449 \n",
       "L 347.35748 171.609449 \n",
       "L 347.35748 41.215748 \n",
       "L 177.27874 41.215748 \n",
       "L 177.27874 171.609449 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_4\">\n",
       "    <path clip-path=\"url(#p9532acebed)\" d=\"M 188.617323 92.23937 \n",
       "L 185.782677 94.365354 \n",
       "L 185.782677 92.23937 \n",
       "L 143.262992 92.23937 \n",
       "L 143.262992 92.23937 \n",
       "L 185.782677 92.23937 \n",
       "L 185.782677 90.113386 \n",
       "L 188.617323 92.23937 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_5\">\n",
       "    <path clip-path=\"url(#p9532acebed)\" d=\"M 222.633071 92.23937 \n",
       "L 225.467717 90.113386 \n",
       "L 225.467717 92.23937 \n",
       "L 267.987402 92.23937 \n",
       "L 267.987402 92.23937 \n",
       "L 225.467717 92.23937 \n",
       "L 225.467717 94.365354 \n",
       "L 222.633071 92.23937 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_6\">\n",
       "    <path clip-path=\"url(#p9532acebed)\" d=\"M 126.255118 109.247244 \n",
       "C 130.765659 109.247244 135.092067 107.455187 138.281501 104.265753 \n",
       "C 141.470935 101.076319 143.262992 96.749911 143.262992 92.23937 \n",
       "C 143.262992 87.728829 141.470935 83.402421 138.281501 80.212987 \n",
       "C 135.092067 77.023553 130.765659 75.231496 126.255118 75.231496 \n",
       "C 121.744577 75.231496 117.418169 77.023553 114.228735 80.212987 \n",
       "C 111.039301 83.402421 109.247244 87.728829 109.247244 92.23937 \n",
       "C 109.247244 96.749911 111.039301 101.076319 114.228735 104.265753 \n",
       "C 117.418169 107.455187 121.744577 109.247244 126.255118 109.247244 \n",
       "L 126.255118 109.247244 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_7\">\n",
       "    <path clip-path=\"url(#p9532acebed)\" d=\"M 284.995276 109.247244 \n",
       "C 289.505817 109.247244 293.832225 107.455187 297.021659 104.265753 \n",
       "C 300.211093 101.076319 302.00315 96.749911 302.00315 92.23937 \n",
       "C 302.00315 87.728829 300.211093 83.402421 297.021659 80.212987 \n",
       "C 293.832225 77.023553 289.505817 75.231496 284.995276 75.231496 \n",
       "C 280.484735 75.231496 276.158327 77.023553 272.968893 80.212987 \n",
       "C 269.779458 83.402421 267.987402 87.728829 267.987402 92.23937 \n",
       "C 267.987402 96.749911 269.779458 101.076319 272.968893 104.265753 \n",
       "C 276.158327 107.455187 280.484735 109.247244 284.995276 109.247244 \n",
       "L 284.995276 109.247244 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_8\">\n",
       "    <path clip-path=\"url(#p9532acebed)\" d=\"M 205.625197 109.247244 \n",
       "C 210.135738 109.247244 214.462146 107.455187 217.65158 104.265753 \n",
       "C 220.841014 101.076319 222.633071 96.749911 222.633071 92.23937 \n",
       "C 222.633071 87.728829 220.841014 83.402421 217.65158 80.212987 \n",
       "C 214.462146 77.023553 210.135738 75.231496 205.625197 75.231496 \n",
       "C 201.114656 75.231496 196.788248 77.023553 193.598814 80.212987 \n",
       "C 190.40938 83.402421 188.617323 87.728829 188.617323 92.23937 \n",
       "C 188.617323 96.749911 190.40938 101.076319 193.598814 104.265753 \n",
       "C 196.788248 107.455187 201.114656 109.247244 205.625197 109.247244 \n",
       "L 205.625197 109.247244 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"matplotlib.axis_1\"/>\n",
       "   <g id=\"matplotlib.axis_2\"/>\n",
       "   <g id=\"text_1\">\n",
       "    <!-- students $s$ -->\n",
       "    <defs>\n",
       "     <path d=\"M 18.3125 70.21875 \n",
       "L 18.3125 54.6875 \n",
       "L 36.8125 54.6875 \n",
       "L 36.8125 47.703125 \n",
       "L 18.3125 47.703125 \n",
       "L 18.3125 18.015625 \n",
       "Q 18.3125 11.328125 20.140625 9.421875 \n",
       "Q 21.96875 7.515625 27.59375 7.515625 \n",
       "L 36.8125 7.515625 \n",
       "L 36.8125 0 \n",
       "L 27.59375 0 \n",
       "Q 17.1875 0 13.234375 3.875 \n",
       "Q 9.28125 7.765625 9.28125 18.015625 \n",
       "L 9.28125 47.703125 \n",
       "L 2.6875 47.703125 \n",
       "L 2.6875 54.6875 \n",
       "L 9.28125 54.6875 \n",
       "L 9.28125 70.21875 \n",
       "z\n",
       "\" id=\"BitstreamVeraSans-Roman-74\"/>\n",
       "     <path d=\"M 43.203125 41 \n",
       "L 41 32.09375 \n",
       "L 39.5 32.09375 \n",
       "Q 37.796875 36.5 35.296875 37.890625 \n",
       "Q 32.796875 39.296875 28.890625 39.296875 \n",
       "Q 25 39.296875 23.046875 37.140625 \n",
       "Q 21.09375 35 21.09375 33 \n",
       "Q 21.09375 31 22.796875 29.546875 \n",
       "Q 24.5 28.09375 27.796875 26.5 \n",
       "Q 33.796875 23.59375 36.140625 21.34375 \n",
       "Q 38.5 19.09375 38.5 15.796875 \n",
       "Q 38.5 9 32.890625 4 \n",
       "Q 27.296875 -1 18.59375 -1 \n",
       "Q 14.09375 -1 11.390625 0.296875 \n",
       "Q 8.703125 1.59375 6.09375 4.5 \n",
       "L 8.59375 14.796875 \n",
       "L 10.09375 14.796875 \n",
       "Q 11.90625 6.09375 21 6.09375 \n",
       "Q 24.40625 6.09375 27.296875 7.84375 \n",
       "Q 30.203125 9.59375 30.203125 12.796875 \n",
       "Q 30.203125 14.296875 28.59375 15.640625 \n",
       "Q 27 17 23.203125 18.90625 \n",
       "Q 17.703125 21.59375 15.25 24.25 \n",
       "Q 12.796875 26.90625 12.796875 30.296875 \n",
       "Q 12.796875 36.5 18 41.390625 \n",
       "Q 23.203125 46.296875 30.90625 46.296875 \n",
       "Q 39.59375 46.296875 43.203125 41 \n",
       "\" id=\"STIXGeneral-Italic-1d634\"/>\n",
       "     <path d=\"M 44.28125 53.078125 \n",
       "L 44.28125 44.578125 \n",
       "Q 40.484375 46.53125 36.375 47.5 \n",
       "Q 32.28125 48.484375 27.875 48.484375 \n",
       "Q 21.1875 48.484375 17.84375 46.4375 \n",
       "Q 14.5 44.390625 14.5 40.28125 \n",
       "Q 14.5 37.15625 16.890625 35.375 \n",
       "Q 19.28125 33.59375 26.515625 31.984375 \n",
       "L 29.59375 31.296875 \n",
       "Q 39.15625 29.25 43.1875 25.515625 \n",
       "Q 47.21875 21.78125 47.21875 15.09375 \n",
       "Q 47.21875 7.46875 41.1875 3.015625 \n",
       "Q 35.15625 -1.421875 24.609375 -1.421875 \n",
       "Q 20.21875 -1.421875 15.453125 -0.5625 \n",
       "Q 10.6875 0.296875 5.421875 2 \n",
       "L 5.421875 11.28125 \n",
       "Q 10.40625 8.6875 15.234375 7.390625 \n",
       "Q 20.0625 6.109375 24.8125 6.109375 \n",
       "Q 31.15625 6.109375 34.5625 8.28125 \n",
       "Q 37.984375 10.453125 37.984375 14.40625 \n",
       "Q 37.984375 18.0625 35.515625 20.015625 \n",
       "Q 33.0625 21.96875 24.703125 23.78125 \n",
       "L 21.578125 24.515625 \n",
       "Q 13.234375 26.265625 9.515625 29.90625 \n",
       "Q 5.8125 33.546875 5.8125 39.890625 \n",
       "Q 5.8125 47.609375 11.28125 51.796875 \n",
       "Q 16.75 56 26.8125 56 \n",
       "Q 31.78125 56 36.171875 55.265625 \n",
       "Q 40.578125 54.546875 44.28125 53.078125 \n",
       "\" id=\"BitstreamVeraSans-Roman-73\"/>\n",
       "     <path id=\"BitstreamVeraSans-Roman-20\"/>\n",
       "     <path d=\"M 54.890625 33.015625 \n",
       "L 54.890625 0 \n",
       "L 45.90625 0 \n",
       "L 45.90625 32.71875 \n",
       "Q 45.90625 40.484375 42.875 44.328125 \n",
       "Q 39.84375 48.1875 33.796875 48.1875 \n",
       "Q 26.515625 48.1875 22.3125 43.546875 \n",
       "Q 18.109375 38.921875 18.109375 30.90625 \n",
       "L 18.109375 0 \n",
       "L 9.078125 0 \n",
       "L 9.078125 54.6875 \n",
       "L 18.109375 54.6875 \n",
       "L 18.109375 46.1875 \n",
       "Q 21.34375 51.125 25.703125 53.5625 \n",
       "Q 30.078125 56 35.796875 56 \n",
       "Q 45.21875 56 50.046875 50.171875 \n",
       "Q 54.890625 44.34375 54.890625 33.015625 \n",
       "\" id=\"BitstreamVeraSans-Roman-6e\"/>\n",
       "     <path d=\"M 45.40625 46.390625 \n",
       "L 45.40625 75.984375 \n",
       "L 54.390625 75.984375 \n",
       "L 54.390625 0 \n",
       "L 45.40625 0 \n",
       "L 45.40625 8.203125 \n",
       "Q 42.578125 3.328125 38.25 0.953125 \n",
       "Q 33.9375 -1.421875 27.875 -1.421875 \n",
       "Q 17.96875 -1.421875 11.734375 6.484375 \n",
       "Q 5.515625 14.40625 5.515625 27.296875 \n",
       "Q 5.515625 40.1875 11.734375 48.09375 \n",
       "Q 17.96875 56 27.875 56 \n",
       "Q 33.9375 56 38.25 53.625 \n",
       "Q 42.578125 51.265625 45.40625 46.390625 \n",
       "M 14.796875 27.296875 \n",
       "Q 14.796875 17.390625 18.875 11.75 \n",
       "Q 22.953125 6.109375 30.078125 6.109375 \n",
       "Q 37.203125 6.109375 41.296875 11.75 \n",
       "Q 45.40625 17.390625 45.40625 27.296875 \n",
       "Q 45.40625 37.203125 41.296875 42.84375 \n",
       "Q 37.203125 48.484375 30.078125 48.484375 \n",
       "Q 22.953125 48.484375 18.875 42.84375 \n",
       "Q 14.796875 37.203125 14.796875 27.296875 \n",
       "\" id=\"BitstreamVeraSans-Roman-64\"/>\n",
       "     <path d=\"M 56.203125 29.59375 \n",
       "L 56.203125 25.203125 \n",
       "L 14.890625 25.203125 \n",
       "Q 15.484375 15.921875 20.484375 11.0625 \n",
       "Q 25.484375 6.203125 34.421875 6.203125 \n",
       "Q 39.59375 6.203125 44.453125 7.46875 \n",
       "Q 49.3125 8.734375 54.109375 11.28125 \n",
       "L 54.109375 2.78125 \n",
       "Q 49.265625 0.734375 44.1875 -0.34375 \n",
       "Q 39.109375 -1.421875 33.890625 -1.421875 \n",
       "Q 20.796875 -1.421875 13.15625 6.1875 \n",
       "Q 5.515625 13.8125 5.515625 26.8125 \n",
       "Q 5.515625 40.234375 12.765625 48.109375 \n",
       "Q 20.015625 56 32.328125 56 \n",
       "Q 43.359375 56 49.78125 48.890625 \n",
       "Q 56.203125 41.796875 56.203125 29.59375 \n",
       "M 47.21875 32.234375 \n",
       "Q 47.125 39.59375 43.09375 43.984375 \n",
       "Q 39.0625 48.390625 32.421875 48.390625 \n",
       "Q 24.90625 48.390625 20.390625 44.140625 \n",
       "Q 15.875 39.890625 15.1875 32.171875 \n",
       "z\n",
       "\" id=\"BitstreamVeraSans-Roman-65\"/>\n",
       "     <path d=\"M 8.5 21.578125 \n",
       "L 8.5 54.6875 \n",
       "L 17.484375 54.6875 \n",
       "L 17.484375 21.921875 \n",
       "Q 17.484375 14.15625 20.5 10.265625 \n",
       "Q 23.53125 6.390625 29.59375 6.390625 \n",
       "Q 36.859375 6.390625 41.078125 11.03125 \n",
       "Q 45.3125 15.671875 45.3125 23.6875 \n",
       "L 45.3125 54.6875 \n",
       "L 54.296875 54.6875 \n",
       "L 54.296875 0 \n",
       "L 45.3125 0 \n",
       "L 45.3125 8.40625 \n",
       "Q 42.046875 3.421875 37.71875 1 \n",
       "Q 33.40625 -1.421875 27.6875 -1.421875 \n",
       "Q 18.265625 -1.421875 13.375 4.4375 \n",
       "Q 8.5 10.296875 8.5 21.578125 \n",
       "\" id=\"BitstreamVeraSans-Roman-75\"/>\n",
       "    </defs>\n",
       "    <g transform=\"translate(68.8929133858 172.278740157)scale(0.18 -0.18)\">\n",
       "     <use transform=\"translate(0.0 0.015625)\" xlink:href=\"#BitstreamVeraSans-Roman-73\"/>\n",
       "     <use transform=\"translate(52.099609375 0.015625)\" xlink:href=\"#BitstreamVeraSans-Roman-74\"/>\n",
       "     <use transform=\"translate(91.30859375 0.015625)\" xlink:href=\"#BitstreamVeraSans-Roman-75\"/>\n",
       "     <use transform=\"translate(154.6875 0.015625)\" xlink:href=\"#BitstreamVeraSans-Roman-64\"/>\n",
       "     <use transform=\"translate(218.1640625 0.015625)\" xlink:href=\"#BitstreamVeraSans-Roman-65\"/>\n",
       "     <use transform=\"translate(279.6875 0.015625)\" xlink:href=\"#BitstreamVeraSans-Roman-6e\"/>\n",
       "     <use transform=\"translate(343.06640625 0.015625)\" xlink:href=\"#BitstreamVeraSans-Roman-74\"/>\n",
       "     <use transform=\"translate(382.275390625 0.015625)\" xlink:href=\"#BitstreamVeraSans-Roman-73\"/>\n",
       "     <use transform=\"translate(434.375 0.015625)\" xlink:href=\"#BitstreamVeraSans-Roman-20\"/>\n",
       "     <use transform=\"translate(466.162109375 0.015625)\" xlink:href=\"#STIXGeneral-Italic-1d634\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"text_2\">\n",
       "    <!-- courses $c$ -->\n",
       "    <defs>\n",
       "     <path d=\"M 48.78125 52.59375 \n",
       "L 48.78125 44.1875 \n",
       "Q 44.96875 46.296875 41.140625 47.34375 \n",
       "Q 37.3125 48.390625 33.40625 48.390625 \n",
       "Q 24.65625 48.390625 19.8125 42.84375 \n",
       "Q 14.984375 37.3125 14.984375 27.296875 \n",
       "Q 14.984375 17.28125 19.8125 11.734375 \n",
       "Q 24.65625 6.203125 33.40625 6.203125 \n",
       "Q 37.3125 6.203125 41.140625 7.25 \n",
       "Q 44.96875 8.296875 48.78125 10.40625 \n",
       "L 48.78125 2.09375 \n",
       "Q 45.015625 0.34375 40.984375 -0.53125 \n",
       "Q 36.96875 -1.421875 32.421875 -1.421875 \n",
       "Q 20.0625 -1.421875 12.78125 6.34375 \n",
       "Q 5.515625 14.109375 5.515625 27.296875 \n",
       "Q 5.515625 40.671875 12.859375 48.328125 \n",
       "Q 20.21875 56 33.015625 56 \n",
       "Q 37.15625 56 41.109375 55.140625 \n",
       "Q 45.0625 54.296875 48.78125 52.59375 \n",
       "\" id=\"BitstreamVeraSans-Roman-63\"/>\n",
       "     <path d=\"M 50.296875 37.09375 \n",
       "L 44.59375 31.703125 \n",
       "L 43 31.703125 \n",
       "Q 41.59375 39.203125 33.5 39.203125 \n",
       "Q 27.09375 39.203125 21.046875 33.09375 \n",
       "Q 15 27 15 16.90625 \n",
       "Q 15 11.796875 17.84375 8.9375 \n",
       "Q 20.703125 6.09375 25.296875 6.09375 \n",
       "Q 33.40625 6.09375 40.796875 16.59375 \n",
       "L 46.40625 13.203125 \n",
       "Q 36.796875 -1 22.90625 -1 \n",
       "Q 15.5 -1 11.09375 3.203125 \n",
       "Q 6.703125 7.40625 6.703125 15 \n",
       "Q 6.703125 28 15.890625 37.140625 \n",
       "Q 25.09375 46.296875 35.703125 46.296875 \n",
       "Q 41.203125 46.296875 45.140625 44 \n",
       "Q 49.09375 41.703125 50.296875 37.09375 \n",
       "\" id=\"STIXGeneral-Italic-1d624\"/>\n",
       "     <path d=\"M 41.109375 46.296875 \n",
       "Q 39.59375 47.171875 37.8125 47.578125 \n",
       "Q 36.03125 48 33.890625 48 \n",
       "Q 26.265625 48 22.1875 43.046875 \n",
       "Q 18.109375 38.09375 18.109375 28.8125 \n",
       "L 18.109375 0 \n",
       "L 9.078125 0 \n",
       "L 9.078125 54.6875 \n",
       "L 18.109375 54.6875 \n",
       "L 18.109375 46.1875 \n",
       "Q 20.953125 51.171875 25.484375 53.578125 \n",
       "Q 30.03125 56 36.53125 56 \n",
       "Q 37.453125 56 38.578125 55.875 \n",
       "Q 39.703125 55.765625 41.0625 55.515625 \n",
       "z\n",
       "\" id=\"BitstreamVeraSans-Roman-72\"/>\n",
       "     <path d=\"M 30.609375 48.390625 \n",
       "Q 23.390625 48.390625 19.1875 42.75 \n",
       "Q 14.984375 37.109375 14.984375 27.296875 \n",
       "Q 14.984375 17.484375 19.15625 11.84375 \n",
       "Q 23.34375 6.203125 30.609375 6.203125 \n",
       "Q 37.796875 6.203125 41.984375 11.859375 \n",
       "Q 46.1875 17.53125 46.1875 27.296875 \n",
       "Q 46.1875 37.015625 41.984375 42.703125 \n",
       "Q 37.796875 48.390625 30.609375 48.390625 \n",
       "M 30.609375 56 \n",
       "Q 42.328125 56 49.015625 48.375 \n",
       "Q 55.71875 40.765625 55.71875 27.296875 \n",
       "Q 55.71875 13.875 49.015625 6.21875 \n",
       "Q 42.328125 -1.421875 30.609375 -1.421875 \n",
       "Q 18.84375 -1.421875 12.171875 6.21875 \n",
       "Q 5.515625 13.875 5.515625 27.296875 \n",
       "Q 5.515625 40.765625 12.171875 48.375 \n",
       "Q 18.84375 56 30.609375 56 \n",
       "\" id=\"BitstreamVeraSans-Roman-6f\"/>\n",
       "    </defs>\n",
       "    <g transform=\"translate(257.278740157 166.609448819)scale(0.18 -0.18)\">\n",
       "     <use xlink:href=\"#BitstreamVeraSans-Roman-63\"/>\n",
       "     <use transform=\"translate(54.98046875 0.0)\" xlink:href=\"#BitstreamVeraSans-Roman-6f\"/>\n",
       "     <use transform=\"translate(116.162109375 0.0)\" xlink:href=\"#BitstreamVeraSans-Roman-75\"/>\n",
       "     <use transform=\"translate(179.541015625 0.0)\" xlink:href=\"#BitstreamVeraSans-Roman-72\"/>\n",
       "     <use transform=\"translate(220.654296875 0.0)\" xlink:href=\"#BitstreamVeraSans-Roman-73\"/>\n",
       "     <use transform=\"translate(272.75390625 0.0)\" xlink:href=\"#BitstreamVeraSans-Roman-65\"/>\n",
       "     <use transform=\"translate(334.27734375 0.0)\" xlink:href=\"#BitstreamVeraSans-Roman-73\"/>\n",
       "     <use transform=\"translate(386.376953125 0.0)\" xlink:href=\"#BitstreamVeraSans-Roman-20\"/>\n",
       "     <use transform=\"translate(418.1640625 0.0)\" xlink:href=\"#STIXGeneral-Italic-1d624\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"text_3\">\n",
       "    <!-- intell. -->\n",
       "    <defs>\n",
       "     <path d=\"M 9.421875 54.6875 \n",
       "L 18.40625 54.6875 \n",
       "L 18.40625 0 \n",
       "L 9.421875 0 \n",
       "z\n",
       "M 9.421875 75.984375 \n",
       "L 18.40625 75.984375 \n",
       "L 18.40625 64.59375 \n",
       "L 9.421875 64.59375 \n",
       "z\n",
       "\" id=\"BitstreamVeraSans-Roman-69\"/>\n",
       "     <path d=\"M 9.421875 75.984375 \n",
       "L 18.40625 75.984375 \n",
       "L 18.40625 0 \n",
       "L 9.421875 0 \n",
       "z\n",
       "\" id=\"BitstreamVeraSans-Roman-6c\"/>\n",
       "     <path d=\"M 10.6875 12.40625 \n",
       "L 21 12.40625 \n",
       "L 21 0 \n",
       "L 10.6875 0 \n",
       "z\n",
       "\" id=\"BitstreamVeraSans-Roman-2e\"/>\n",
       "    </defs>\n",
       "    <g transform=\"translate(115.08574311 94.4468700787)scale(0.08 -0.08)\">\n",
       "     <use xlink:href=\"#BitstreamVeraSans-Roman-69\"/>\n",
       "     <use x=\"27.783203125\" xlink:href=\"#BitstreamVeraSans-Roman-6e\"/>\n",
       "     <use x=\"91.162109375\" xlink:href=\"#BitstreamVeraSans-Roman-74\"/>\n",
       "     <use x=\"130.37109375\" xlink:href=\"#BitstreamVeraSans-Roman-65\"/>\n",
       "     <use x=\"191.89453125\" xlink:href=\"#BitstreamVeraSans-Roman-6c\"/>\n",
       "     <use x=\"219.677734375\" xlink:href=\"#BitstreamVeraSans-Roman-6c\"/>\n",
       "     <use x=\"247.4609375\" xlink:href=\"#BitstreamVeraSans-Roman-2e\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"text_4\">\n",
       "    <!-- diffic. -->\n",
       "    <defs>\n",
       "     <path d=\"M 37.109375 75.984375 \n",
       "L 37.109375 68.5 \n",
       "L 28.515625 68.5 \n",
       "Q 23.6875 68.5 21.796875 66.546875 \n",
       "Q 19.921875 64.59375 19.921875 59.515625 \n",
       "L 19.921875 54.6875 \n",
       "L 34.71875 54.6875 \n",
       "L 34.71875 47.703125 \n",
       "L 19.921875 47.703125 \n",
       "L 19.921875 0 \n",
       "L 10.890625 0 \n",
       "L 10.890625 47.703125 \n",
       "L 2.296875 47.703125 \n",
       "L 2.296875 54.6875 \n",
       "L 10.890625 54.6875 \n",
       "L 10.890625 58.5 \n",
       "Q 10.890625 67.625 15.140625 71.796875 \n",
       "Q 19.390625 75.984375 28.609375 75.984375 \n",
       "z\n",
       "\" id=\"BitstreamVeraSans-Roman-66\"/>\n",
       "    </defs>\n",
       "    <g transform=\"translate(273.946525591 94.4468700787)scale(0.08 -0.08)\">\n",
       "     <use xlink:href=\"#BitstreamVeraSans-Roman-64\"/>\n",
       "     <use x=\"63.4765625\" xlink:href=\"#BitstreamVeraSans-Roman-69\"/>\n",
       "     <use x=\"91.259765625\" xlink:href=\"#BitstreamVeraSans-Roman-66\"/>\n",
       "     <use x=\"126.46484375\" xlink:href=\"#BitstreamVeraSans-Roman-66\"/>\n",
       "     <use x=\"161.669921875\" xlink:href=\"#BitstreamVeraSans-Roman-69\"/>\n",
       "     <use x=\"189.453125\" xlink:href=\"#BitstreamVeraSans-Roman-63\"/>\n",
       "     <use x=\"244.43359375\" xlink:href=\"#BitstreamVeraSans-Roman-2e\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"text_5\">\n",
       "    <!-- grade -->\n",
       "    <defs>\n",
       "     <path d=\"M 45.40625 27.984375 \n",
       "Q 45.40625 37.75 41.375 43.109375 \n",
       "Q 37.359375 48.484375 30.078125 48.484375 \n",
       "Q 22.859375 48.484375 18.828125 43.109375 \n",
       "Q 14.796875 37.75 14.796875 27.984375 \n",
       "Q 14.796875 18.265625 18.828125 12.890625 \n",
       "Q 22.859375 7.515625 30.078125 7.515625 \n",
       "Q 37.359375 7.515625 41.375 12.890625 \n",
       "Q 45.40625 18.265625 45.40625 27.984375 \n",
       "M 54.390625 6.78125 \n",
       "Q 54.390625 -7.171875 48.1875 -13.984375 \n",
       "Q 42 -20.796875 29.203125 -20.796875 \n",
       "Q 24.46875 -20.796875 20.265625 -20.09375 \n",
       "Q 16.0625 -19.390625 12.109375 -17.921875 \n",
       "L 12.109375 -9.1875 \n",
       "Q 16.0625 -11.328125 19.921875 -12.34375 \n",
       "Q 23.78125 -13.375 27.78125 -13.375 \n",
       "Q 36.625 -13.375 41.015625 -8.765625 \n",
       "Q 45.40625 -4.15625 45.40625 5.171875 \n",
       "L 45.40625 9.625 \n",
       "Q 42.625 4.78125 38.28125 2.390625 \n",
       "Q 33.9375 0 27.875 0 \n",
       "Q 17.828125 0 11.671875 7.65625 \n",
       "Q 5.515625 15.328125 5.515625 27.984375 \n",
       "Q 5.515625 40.671875 11.671875 48.328125 \n",
       "Q 17.828125 56 27.875 56 \n",
       "Q 33.9375 56 38.28125 53.609375 \n",
       "Q 42.625 51.21875 45.40625 46.390625 \n",
       "L 45.40625 54.6875 \n",
       "L 54.390625 54.6875 \n",
       "z\n",
       "\" id=\"BitstreamVeraSans-Roman-67\"/>\n",
       "     <path d=\"M 34.28125 27.484375 \n",
       "Q 23.390625 27.484375 19.1875 25 \n",
       "Q 14.984375 22.515625 14.984375 16.5 \n",
       "Q 14.984375 11.71875 18.140625 8.90625 \n",
       "Q 21.296875 6.109375 26.703125 6.109375 \n",
       "Q 34.1875 6.109375 38.703125 11.40625 \n",
       "Q 43.21875 16.703125 43.21875 25.484375 \n",
       "L 43.21875 27.484375 \n",
       "z\n",
       "M 52.203125 31.203125 \n",
       "L 52.203125 0 \n",
       "L 43.21875 0 \n",
       "L 43.21875 8.296875 \n",
       "Q 40.140625 3.328125 35.546875 0.953125 \n",
       "Q 30.953125 -1.421875 24.3125 -1.421875 \n",
       "Q 15.921875 -1.421875 10.953125 3.296875 \n",
       "Q 6 8.015625 6 15.921875 \n",
       "Q 6 25.140625 12.171875 29.828125 \n",
       "Q 18.359375 34.515625 30.609375 34.515625 \n",
       "L 43.21875 34.515625 \n",
       "L 43.21875 35.40625 \n",
       "Q 43.21875 41.609375 39.140625 45 \n",
       "Q 35.0625 48.390625 27.6875 48.390625 \n",
       "Q 23 48.390625 18.546875 47.265625 \n",
       "Q 14.109375 46.140625 10.015625 43.890625 \n",
       "L 10.015625 52.203125 \n",
       "Q 14.9375 54.109375 19.578125 55.046875 \n",
       "Q 24.21875 56 28.609375 56 \n",
       "Q 40.484375 56 46.34375 49.84375 \n",
       "Q 52.203125 43.703125 52.203125 31.203125 \n",
       "\" id=\"BitstreamVeraSans-Roman-61\"/>\n",
       "    </defs>\n",
       "    <g transform=\"translate(193.98957185 94.4468700787)scale(0.08 -0.08)\">\n",
       "     <use xlink:href=\"#BitstreamVeraSans-Roman-67\"/>\n",
       "     <use x=\"63.4765625\" xlink:href=\"#BitstreamVeraSans-Roman-72\"/>\n",
       "     <use x=\"104.58984375\" xlink:href=\"#BitstreamVeraSans-Roman-61\"/>\n",
       "     <use x=\"165.869140625\" xlink:href=\"#BitstreamVeraSans-Roman-64\"/>\n",
       "     <use x=\"229.345703125\" xlink:href=\"#BitstreamVeraSans-Roman-65\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "  </g>\n",
       " </g>\n",
       " <defs>\n",
       "  <clipPath id=\"p9532acebed\">\n",
       "   <rect height=\"170.078740157\" width=\"340.157480315\" x=\"7.2\" y=\"7.2\"/>\n",
       "  </clipPath>\n",
       " </defs>\n",
       "</svg>\n"
      ],
      "text/plain": [
       "<matplotlib.figure.Figure at 0x7feb96d84358>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "pgm = daft.PGM([6, 3], origin=[-0.5, 0.5])\n",
    "add_node(pgm, 'I', 'intell.', 1.6, 2, label_params={'size':8})\n",
    "add_node(pgm, 'D', 'diffic.', 4.4, 2, label_params={'size':8})\n",
    "add_node(pgm, 'G', 'grade', 3, 2, label_params={'size':8})\n",
    "add_edges(pgm, [\n",
    "        ('I', 'G'),\n",
    "        ('D', 'G')\n",
    "    ])\n",
    "pgm.add_plate(daft.Plate((0.5,0.5,3,2.5), label='students $s$'))\n",
    "pgm.add_plate(daft.Plate((2.5,0.6,3,2.3), label='courses $c$', label_offset=(80, 5)))\n",
    "pgm.render()\n",
    "save('bn_plate_model_02_overlapping')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "image/svg+xml": [
       "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"no\"?>\n",
       "<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\n",
       "  \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n",
       "<!-- Created with matplotlib (http://matplotlib.org/) -->\n",
       "<svg height=\"184pt\" version=\"1.1\" viewBox=\"0 0 354 184\" width=\"354pt\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n",
       " <defs>\n",
       "  <style type=\"text/css\">\n",
       "*{stroke-linecap:butt;stroke-linejoin:round;stroke-miterlimit:100000;}\n",
       "  </style>\n",
       " </defs>\n",
       " <g id=\"figure_1\">\n",
       "  <g id=\"patch_1\">\n",
       "   <path d=\"M 0 184.47874 \n",
       "L 354.55748 184.47874 \n",
       "L 354.55748 0 \n",
       "L 0 0 \n",
       "L 0 184.47874 \n",
       "z\n",
       "\" style=\"fill:none;\"/>\n",
       "  </g>\n",
       "  <g id=\"axes_1\">\n",
       "   <g id=\"patch_2\">\n",
       "    <path clip-path=\"url(#pbf53d3b26e)\" d=\"M 74.449381 132.641695 \n",
       "L 73.227587 129.315699 \n",
       "L 75.263911 129.926597 \n",
       "L 98.690776 51.837045 \n",
       "L 98.690776 51.837045 \n",
       "L 75.263911 129.926597 \n",
       "L 77.300234 130.537494 \n",
       "L 74.449381 132.641695 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_3\">\n",
       "    <path clip-path=\"url(#pbf53d3b26e)\" d=\"M 63.245639 133.140869 \n",
       "L 60.218951 131.298537 \n",
       "L 62.192878 130.508966 \n",
       "L 53.201605 108.030785 \n",
       "L 53.201605 108.030785 \n",
       "L 62.192878 130.508966 \n",
       "L 64.166805 129.719396 \n",
       "L 63.245639 133.140869 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_4\">\n",
       "    <path clip-path=\"url(#pbf53d3b26e)\" d=\"M 132.706524 132.641695 \n",
       "L 129.855671 130.537494 \n",
       "L 131.891995 129.926597 \n",
       "L 108.465129 51.837045 \n",
       "L 108.465129 51.837045 \n",
       "L 131.891995 129.926597 \n",
       "L 133.928318 129.315699 \n",
       "L 132.706524 132.641695 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_5\">\n",
       "    <path clip-path=\"url(#pbf53d3b26e)\" d=\"M 143.910267 133.140869 \n",
       "L 142.989101 129.719396 \n",
       "L 144.963028 130.508966 \n",
       "L 153.9543 108.030785 \n",
       "L 153.9543 108.030785 \n",
       "L 144.963028 130.508966 \n",
       "L 146.936954 131.298537 \n",
       "L 143.910267 133.140869 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_6\">\n",
       "    <path clip-path=\"url(#pbf53d3b26e)\" d=\"M 244.528122 132.641695 \n",
       "L 243.306327 129.315699 \n",
       "L 245.342651 129.926597 \n",
       "L 268.769516 51.837045 \n",
       "L 268.769516 51.837045 \n",
       "L 245.342651 129.926597 \n",
       "L 247.378975 130.537494 \n",
       "L 244.528122 132.641695 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_7\">\n",
       "    <path clip-path=\"url(#pbf53d3b26e)\" d=\"M 233.324379 133.140869 \n",
       "L 230.297691 131.298537 \n",
       "L 232.271618 130.508966 \n",
       "L 223.280345 108.030785 \n",
       "L 223.280345 108.030785 \n",
       "L 232.271618 130.508966 \n",
       "L 234.245545 129.719396 \n",
       "L 233.324379 133.140869 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_8\">\n",
       "    <path clip-path=\"url(#pbf53d3b26e)\" d=\"M 302.785264 132.641695 \n",
       "L 299.934411 130.537494 \n",
       "L 301.970735 129.926597 \n",
       "L 278.54387 51.837045 \n",
       "L 278.54387 51.837045 \n",
       "L 301.970735 129.926597 \n",
       "L 304.007058 129.315699 \n",
       "L 302.785264 132.641695 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_9\">\n",
       "    <path clip-path=\"url(#pbf53d3b26e)\" d=\"M 313.989007 133.140869 \n",
       "L 313.067841 129.719396 \n",
       "L 315.041768 130.508966 \n",
       "L 324.03304 108.030785 \n",
       "L 324.03304 108.030785 \n",
       "L 315.041768 130.508966 \n",
       "L 317.015695 131.298537 \n",
       "L 313.989007 133.140869 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_10\">\n",
       "    <path clip-path=\"url(#pbf53d3b26e)\" d=\"M 307.672441 165.940157 \n",
       "C 312.182982 165.940157 316.50939 164.148101 319.698824 160.958667 \n",
       "C 322.888258 157.769232 324.680315 153.442824 324.680315 148.932283 \n",
       "C 324.680315 144.421743 322.888258 140.095334 319.698824 136.9059 \n",
       "C 316.50939 133.716466 312.182982 131.924409 307.672441 131.924409 \n",
       "C 303.1619 131.924409 298.835492 133.716466 295.646058 136.9059 \n",
       "C 292.456624 140.095334 290.664567 144.421743 290.664567 148.932283 \n",
       "C 290.664567 153.442824 292.456624 157.769232 295.646058 160.958667 \n",
       "C 298.835492 164.148101 303.1619 165.940157 307.672441 165.940157 \n",
       "L 307.672441 165.940157 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_11\">\n",
       "    <path clip-path=\"url(#pbf53d3b26e)\" d=\"M 330.349606 109.247244 \n",
       "C 334.860147 109.247244 339.186555 107.455187 342.375989 104.265753 \n",
       "C 345.565423 101.076319 347.35748 96.749911 347.35748 92.23937 \n",
       "C 347.35748 87.728829 345.565423 83.402421 342.375989 80.212987 \n",
       "C 339.186555 77.023553 334.860147 75.231496 330.349606 75.231496 \n",
       "C 325.839065 75.231496 321.512657 77.023553 318.323223 80.212987 \n",
       "C 315.133789 83.402421 313.341732 87.728829 313.341732 92.23937 \n",
       "C 313.341732 96.749911 315.133789 101.076319 318.323223 104.265753 \n",
       "C 321.512657 107.455187 325.839065 109.247244 330.349606 109.247244 \n",
       "L 330.349606 109.247244 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_12\">\n",
       "    <path clip-path=\"url(#pbf53d3b26e)\" d=\"M 137.593701 165.940157 \n",
       "C 142.104242 165.940157 146.43065 164.148101 149.620084 160.958667 \n",
       "C 152.809518 157.769232 154.601575 153.442824 154.601575 148.932283 \n",
       "C 154.601575 144.421743 152.809518 140.095334 149.620084 136.9059 \n",
       "C 146.43065 133.716466 142.104242 131.924409 137.593701 131.924409 \n",
       "C 133.08316 131.924409 128.756752 133.716466 125.567318 136.9059 \n",
       "C 122.377884 140.095334 120.585827 144.421743 120.585827 148.932283 \n",
       "C 120.585827 153.442824 122.377884 157.769232 125.567318 160.958667 \n",
       "C 128.756752 164.148101 133.08316 165.940157 137.593701 165.940157 \n",
       "L 137.593701 165.940157 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_13\">\n",
       "    <path clip-path=\"url(#pbf53d3b26e)\" d=\"M 46.885039 109.247244 \n",
       "C 51.39558 109.247244 55.721988 107.455187 58.911422 104.265753 \n",
       "C 62.100856 101.076319 63.892913 96.749911 63.892913 92.23937 \n",
       "C 63.892913 87.728829 62.100856 83.402421 58.911422 80.212987 \n",
       "C 55.721988 77.023553 51.39558 75.231496 46.885039 75.231496 \n",
       "C 42.374498 75.231496 38.04809 77.023553 34.858656 80.212987 \n",
       "C 31.669222 83.402421 29.877165 87.728829 29.877165 92.23937 \n",
       "C 29.877165 96.749911 31.669222 101.076319 34.858656 104.265753 \n",
       "C 38.04809 107.455187 42.374498 109.247244 46.885039 109.247244 \n",
       "L 46.885039 109.247244 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_14\">\n",
       "    <path clip-path=\"url(#pbf53d3b26e)\" d=\"M 239.640945 165.940157 \n",
       "C 244.151486 165.940157 248.477894 164.148101 251.667328 160.958667 \n",
       "C 254.856762 157.769232 256.648819 153.442824 256.648819 148.932283 \n",
       "C 256.648819 144.421743 254.856762 140.095334 251.667328 136.9059 \n",
       "C 248.477894 133.716466 244.151486 131.924409 239.640945 131.924409 \n",
       "C 235.130404 131.924409 230.803996 133.716466 227.614562 136.9059 \n",
       "C 224.425128 140.095334 222.633071 144.421743 222.633071 148.932283 \n",
       "C 222.633071 153.442824 224.425128 157.769232 227.614562 160.958667 \n",
       "C 230.803996 164.148101 235.130404 165.940157 239.640945 165.940157 \n",
       "L 239.640945 165.940157 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_15\">\n",
       "    <path clip-path=\"url(#pbf53d3b26e)\" d=\"M 160.270866 109.247244 \n",
       "C 164.781407 109.247244 169.107815 107.455187 172.297249 104.265753 \n",
       "C 175.486683 101.076319 177.27874 96.749911 177.27874 92.23937 \n",
       "C 177.27874 87.728829 175.486683 83.402421 172.297249 80.212987 \n",
       "C 169.107815 77.023553 164.781407 75.231496 160.270866 75.231496 \n",
       "C 155.760325 75.231496 151.433917 77.023553 148.244483 80.212987 \n",
       "C 145.055049 83.402421 143.262992 87.728829 143.262992 92.23937 \n",
       "C 143.262992 96.749911 145.055049 101.076319 148.244483 104.265753 \n",
       "C 151.433917 107.455187 155.760325 109.247244 160.270866 109.247244 \n",
       "L 160.270866 109.247244 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_16\">\n",
       "    <path clip-path=\"url(#pbf53d3b26e)\" d=\"M 69.562205 165.940157 \n",
       "C 74.072746 165.940157 78.399154 164.148101 81.588588 160.958667 \n",
       "C 84.778022 157.769232 86.570079 153.442824 86.570079 148.932283 \n",
       "C 86.570079 144.421743 84.778022 140.095334 81.588588 136.9059 \n",
       "C 78.399154 133.716466 74.072746 131.924409 69.562205 131.924409 \n",
       "C 65.051664 131.924409 60.725256 133.716466 57.535822 136.9059 \n",
       "C 54.346388 140.095334 52.554331 144.421743 52.554331 148.932283 \n",
       "C 52.554331 153.442824 54.346388 157.769232 57.535822 160.958667 \n",
       "C 60.725256 164.148101 65.051664 165.940157 69.562205 165.940157 \n",
       "L 69.562205 165.940157 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_17\">\n",
       "    <path clip-path=\"url(#pbf53d3b26e)\" d=\"M 216.96378 109.247244 \n",
       "C 221.47432 109.247244 225.800729 107.455187 228.990163 104.265753 \n",
       "C 232.179597 101.076319 233.971654 96.749911 233.971654 92.23937 \n",
       "C 233.971654 87.728829 232.179597 83.402421 228.990163 80.212987 \n",
       "C 225.800729 77.023553 221.47432 75.231496 216.96378 75.231496 \n",
       "C 212.453239 75.231496 208.126831 77.023553 204.937396 80.212987 \n",
       "C 201.747962 83.402421 199.955906 87.728829 199.955906 92.23937 \n",
       "C 199.955906 96.749911 201.747962 101.076319 204.937396 104.265753 \n",
       "C 208.126831 107.455187 212.453239 109.247244 216.96378 109.247244 \n",
       "L 216.96378 109.247244 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_18\">\n",
       "    <path clip-path=\"url(#pbf53d3b26e)\" d=\"M 103.577953 52.554331 \n",
       "C 108.088494 52.554331 112.414902 50.762274 115.604336 47.57284 \n",
       "C 118.79377 44.383406 120.585827 40.056998 120.585827 35.546457 \n",
       "C 120.585827 31.035916 118.79377 26.709508 115.604336 23.520074 \n",
       "C 112.414902 20.33064 108.088494 18.538583 103.577953 18.538583 \n",
       "C 99.067412 18.538583 94.741004 20.33064 91.55157 23.520074 \n",
       "C 88.362136 26.709508 86.570079 31.035916 86.570079 35.546457 \n",
       "C 86.570079 40.056998 88.362136 44.383406 91.55157 47.57284 \n",
       "C 94.741004 50.762274 99.067412 52.554331 103.577953 52.554331 \n",
       "L 103.577953 52.554331 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_19\">\n",
       "    <path clip-path=\"url(#pbf53d3b26e)\" d=\"M 273.656693 52.554331 \n",
       "C 278.167234 52.554331 282.493642 50.762274 285.683076 47.57284 \n",
       "C 288.87251 44.383406 290.664567 40.056998 290.664567 35.546457 \n",
       "C 290.664567 31.035916 288.87251 26.709508 285.683076 23.520074 \n",
       "C 282.493642 20.33064 278.167234 18.538583 273.656693 18.538583 \n",
       "C 269.146152 18.538583 264.819744 20.33064 261.63031 23.520074 \n",
       "C 258.440876 26.709508 256.648819 31.035916 256.648819 35.546457 \n",
       "C 256.648819 40.056998 258.440876 44.383406 261.63031 47.57284 \n",
       "C 264.819744 50.762274 269.146152 52.554331 273.656693 52.554331 \n",
       "L 273.656693 52.554331 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"matplotlib.axis_1\"/>\n",
       "   <g id=\"matplotlib.axis_2\"/>\n",
       "   <g id=\"text_1\">\n",
       "    <!-- $G(s_2, c_2)$ -->\n",
       "    <defs>\n",
       "     <path d=\"M 46.90625 7.09375 \n",
       "L 44 0 \n",
       "L 3.5 0 \n",
       "L 3.5 2.09375 \n",
       "L 21 23.5 \n",
       "L 21 23.40625 \n",
       "L 26.59375 30.203125 \n",
       "Q 30.5 34.90625 32.09375 36.953125 \n",
       "Q 33.703125 39 35.203125 41.953125 \n",
       "Q 36.703125 44.90625 36.703125 47.5 \n",
       "Q 36.703125 53.703125 33.34375 57.09375 \n",
       "Q 30 60.5 24.203125 60.5 \n",
       "Q 19.59375 60.5 15.75 56.703125 \n",
       "Q 11.90625 52.90625 10.90625 45.90625 \n",
       "L 3.703125 47.59375 \n",
       "Q 5.296875 56.5 11.1875 62.046875 \n",
       "Q 17.09375 67.59375 24.90625 67.59375 \n",
       "Q 33.59375 67.59375 39.09375 62.1875 \n",
       "Q 44.59375 56.796875 44.59375 49.09375 \n",
       "Q 44.59375 43.5 42.5 39.453125 \n",
       "Q 40.40625 35.40625 33.703125 27 \n",
       "L 17.703125 7.09375 \n",
       "z\n",
       "\" id=\"STIXGeneral-Regular-1d7e4\"/>\n",
       "     <path d=\"M 8.296875 -14.09375 \n",
       "L 7.296875 -12.203125 \n",
       "Q 15.59375 -6.59375 15.59375 -1.5 \n",
       "Q 15.59375 -0.203125 14.203125 -0.203125 \n",
       "Q 13.796875 -0.203125 12.84375 -0.390625 \n",
       "Q 11.90625 -0.59375 11.296875 -0.59375 \n",
       "Q 5.5 -0.59375 5.5 4.5 \n",
       "Q 5.5 7.09375 7.140625 8.640625 \n",
       "Q 8.796875 10.203125 11.5 10.203125 \n",
       "Q 14.90625 10.203125 17.203125 7.75 \n",
       "Q 19.5 5.296875 19.5 1.5 \n",
       "Q 19.5 -3.09375 16.453125 -7.390625 \n",
       "Q 13.40625 -11.703125 8.296875 -14.09375 \n",
       "\" id=\"STIXGeneral-Regular-2c\"/>\n",
       "     <path d=\"M 50.296875 37.09375 \n",
       "L 44.59375 31.703125 \n",
       "L 43 31.703125 \n",
       "Q 41.59375 39.203125 33.5 39.203125 \n",
       "Q 27.09375 39.203125 21.046875 33.09375 \n",
       "Q 15 27 15 16.90625 \n",
       "Q 15 11.796875 17.84375 8.9375 \n",
       "Q 20.703125 6.09375 25.296875 6.09375 \n",
       "Q 33.40625 6.09375 40.796875 16.59375 \n",
       "L 46.40625 13.203125 \n",
       "Q 36.796875 -1 22.90625 -1 \n",
       "Q 15.5 -1 11.09375 3.203125 \n",
       "Q 6.703125 7.40625 6.703125 15 \n",
       "Q 6.703125 28 15.890625 37.140625 \n",
       "Q 25.09375 46.296875 35.703125 46.296875 \n",
       "Q 41.203125 46.296875 45.140625 44 \n",
       "Q 49.09375 41.703125 50.296875 37.09375 \n",
       "\" id=\"STIXGeneral-Italic-1d624\"/>\n",
       "     <path d=\"M 43.203125 41 \n",
       "L 41 32.09375 \n",
       "L 39.5 32.09375 \n",
       "Q 37.796875 36.5 35.296875 37.890625 \n",
       "Q 32.796875 39.296875 28.890625 39.296875 \n",
       "Q 25 39.296875 23.046875 37.140625 \n",
       "Q 21.09375 35 21.09375 33 \n",
       "Q 21.09375 31 22.796875 29.546875 \n",
       "Q 24.5 28.09375 27.796875 26.5 \n",
       "Q 33.796875 23.59375 36.140625 21.34375 \n",
       "Q 38.5 19.09375 38.5 15.796875 \n",
       "Q 38.5 9 32.890625 4 \n",
       "Q 27.296875 -1 18.59375 -1 \n",
       "Q 14.09375 -1 11.390625 0.296875 \n",
       "Q 8.703125 1.59375 6.09375 4.5 \n",
       "L 8.59375 14.796875 \n",
       "L 10.09375 14.796875 \n",
       "Q 11.90625 6.09375 21 6.09375 \n",
       "Q 24.40625 6.09375 27.296875 7.84375 \n",
       "Q 30.203125 9.59375 30.203125 12.796875 \n",
       "Q 30.203125 14.296875 28.59375 15.640625 \n",
       "Q 27 17 23.203125 18.90625 \n",
       "Q 17.703125 21.59375 15.25 24.25 \n",
       "Q 12.796875 26.90625 12.796875 30.296875 \n",
       "Q 12.796875 36.5 18 41.390625 \n",
       "Q 23.203125 46.296875 30.90625 46.296875 \n",
       "Q 39.59375 46.296875 43.203125 41 \n",
       "\" id=\"STIXGeneral-Italic-1d634\"/>\n",
       "     <path d=\"M 2.90625 66 \n",
       "L 4.09375 67.59375 \n",
       "Q 15.5 60.796875 22 49.1875 \n",
       "Q 28.5 37.59375 28.5 24.703125 \n",
       "Q 28.5 -2.59375 3.796875 -17.703125 \n",
       "L 2.90625 -16.09375 \n",
       "Q 13.203125 -7.59375 16.546875 0.84375 \n",
       "Q 19.90625 9.296875 19.90625 24.40625 \n",
       "Q 19.90625 39.59375 16.546875 48.75 \n",
       "Q 13.203125 57.90625 2.90625 66 \n",
       "\" id=\"STIXGeneral-Regular-29\"/>\n",
       "     <path d=\"M 30.40625 -16.09375 \n",
       "L 29.203125 -17.703125 \n",
       "Q 17.59375 -11.09375 11.1875 0.5 \n",
       "Q 4.796875 12.09375 4.796875 25.203125 \n",
       "Q 4.796875 52.90625 29.5 67.59375 \n",
       "L 30.40625 66 \n",
       "Q 20.203125 57.296875 16.796875 48.84375 \n",
       "Q 13.40625 40.40625 13.40625 25.5 \n",
       "Q 13.40625 10.703125 16.90625 1.5 \n",
       "Q 20.40625 -7.703125 30.40625 -16.09375 \n",
       "\" id=\"STIXGeneral-Regular-28\"/>\n",
       "     <path d=\"M 75.5 56.5 \n",
       "L 73 46.203125 \n",
       "L 71.09375 46.203125 \n",
       "Q 67.90625 60 52.203125 60 \n",
       "Q 42.796875 60 35.046875 54.953125 \n",
       "Q 27.296875 49.90625 23.140625 42.203125 \n",
       "Q 19 34.5 19 26.203125 \n",
       "Q 19 17.5 24.203125 11.84375 \n",
       "Q 29.40625 6.203125 39.40625 6.203125 \n",
       "Q 47.703125 6.203125 52.046875 8 \n",
       "Q 56.40625 9.796875 57 12.296875 \n",
       "L 61 28.09375 \n",
       "L 52.09375 28.09375 \n",
       "L 52.09375 35.703125 \n",
       "L 71.59375 35.703125 \n",
       "L 64.09375 5.90625 \n",
       "Q 59.59375 3.296875 57.1875 2.1875 \n",
       "Q 54.796875 1.09375 49.34375 -0.15625 \n",
       "Q 43.90625 -1.40625 37.09375 -1.40625 \n",
       "Q 24.203125 -1.40625 16.953125 5.34375 \n",
       "Q 9.703125 12.09375 9.703125 23.40625 \n",
       "Q 9.703125 32.09375 13.34375 40.25 \n",
       "Q 17 48.40625 23.046875 54.40625 \n",
       "Q 29.09375 60.40625 37.296875 64 \n",
       "Q 45.5 67.59375 54.09375 67.59375 \n",
       "Q 70.59375 67.59375 75.5 56.5 \n",
       "\" id=\"STIXGeneral-Italic-1d60e\"/>\n",
       "    </defs>\n",
       "    <g transform=\"translate(289.192440945 151.967595965)scale(0.11 -0.11)\">\n",
       "     <use transform=\"translate(0.0 0.40625)\" xlink:href=\"#STIXGeneral-Italic-1d60e\"/>\n",
       "     <use transform=\"translate(69.49998474121094 0.40625)\" xlink:href=\"#STIXGeneral-Regular-28\"/>\n",
       "     <use transform=\"translate(102.79997253417969 0.40625)\" xlink:href=\"#STIXGeneral-Italic-1d634\"/>\n",
       "     <use transform=\"translate(141.69996643066406 -13.182812499999997)scale(0.7)\" xlink:href=\"#STIXGeneral-Regular-1d7e4\"/>\n",
       "     <use transform=\"translate(178.9647994995117 0.40625)\" xlink:href=\"#STIXGeneral-Regular-2c\"/>\n",
       "     <use transform=\"translate(219.08478240966798 0.40625)\" xlink:href=\"#STIXGeneral-Italic-1d624\"/>\n",
       "     <use transform=\"translate(264.68477325439454 -13.182812499999997)scale(0.7)\" xlink:href=\"#STIXGeneral-Regular-1d7e4\"/>\n",
       "     <use transform=\"translate(301.94960632324216 0.40625)\" xlink:href=\"#STIXGeneral-Regular-29\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"text_2\">\n",
       "    <!-- $I(s_2, c_2)$ -->\n",
       "    <defs>\n",
       "     <path d=\"M 51.203125 66.203125 \n",
       "L 50.203125 58.796875 \n",
       "L 39.09375 58.796875 \n",
       "L 26.296875 7.40625 \n",
       "L 37.40625 7.40625 \n",
       "L 34.703125 0 \n",
       "L 5.90625 0 \n",
       "L 6.296875 7.40625 \n",
       "L 17.40625 7.40625 \n",
       "L 30.203125 58.796875 \n",
       "L 19.09375 58.796875 \n",
       "L 22.40625 66.203125 \n",
       "z\n",
       "\" id=\"STIXGeneral-Italic-1d610\"/>\n",
       "    </defs>\n",
       "    <g transform=\"translate(313.519606299 95.2746825787)scale(0.11 -0.11)\">\n",
       "     <use transform=\"translate(0.0 0.40625)\" xlink:href=\"#STIXGeneral-Italic-1d610\"/>\n",
       "     <use transform=\"translate(40.09999084472656 0.40625)\" xlink:href=\"#STIXGeneral-Regular-28\"/>\n",
       "     <use transform=\"translate(73.39997863769531 0.40625)\" xlink:href=\"#STIXGeneral-Italic-1d634\"/>\n",
       "     <use transform=\"translate(112.29997253417969 -13.182812499999997)scale(0.7)\" xlink:href=\"#STIXGeneral-Regular-1d7e4\"/>\n",
       "     <use transform=\"translate(149.56480560302734 0.40625)\" xlink:href=\"#STIXGeneral-Regular-2c\"/>\n",
       "     <use transform=\"translate(189.6847885131836 0.40625)\" xlink:href=\"#STIXGeneral-Italic-1d624\"/>\n",
       "     <use transform=\"translate(235.28477935791017 -13.182812499999997)scale(0.7)\" xlink:href=\"#STIXGeneral-Regular-1d7e4\"/>\n",
       "     <use transform=\"translate(272.5496124267578 0.40625)\" xlink:href=\"#STIXGeneral-Regular-29\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"text_3\">\n",
       "    <!-- $G(s_2, c_1)$ -->\n",
       "    <defs>\n",
       "     <path d=\"M 30.203125 0 \n",
       "L 22.296875 0 \n",
       "L 22.296875 57 \n",
       "Q 20.09375 56 15.75 53.75 \n",
       "Q 11.40625 51.5 10.796875 51.203125 \n",
       "L 10.796875 58.5 \n",
       "L 28.796875 67.703125 \n",
       "L 30.203125 67.203125 \n",
       "z\n",
       "\" id=\"STIXGeneral-Regular-1d7e3\"/>\n",
       "    </defs>\n",
       "    <g transform=\"translate(119.113700787 151.967595965)scale(0.11 -0.11)\">\n",
       "     <use transform=\"translate(0.0 0.40625)\" xlink:href=\"#STIXGeneral-Italic-1d60e\"/>\n",
       "     <use transform=\"translate(69.49998474121094 0.40625)\" xlink:href=\"#STIXGeneral-Regular-28\"/>\n",
       "     <use transform=\"translate(102.79997253417969 0.40625)\" xlink:href=\"#STIXGeneral-Italic-1d634\"/>\n",
       "     <use transform=\"translate(141.69996643066406 -13.182812499999997)scale(0.7)\" xlink:href=\"#STIXGeneral-Regular-1d7e4\"/>\n",
       "     <use transform=\"translate(178.9647994995117 0.40625)\" xlink:href=\"#STIXGeneral-Regular-2c\"/>\n",
       "     <use transform=\"translate(219.08478240966798 0.40625)\" xlink:href=\"#STIXGeneral-Italic-1d624\"/>\n",
       "     <use transform=\"translate(264.68477325439454 -13.182812499999997)scale(0.7)\" xlink:href=\"#STIXGeneral-Regular-1d7e3\"/>\n",
       "     <use transform=\"translate(301.94960632324216 0.40625)\" xlink:href=\"#STIXGeneral-Regular-29\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"text_4\">\n",
       "    <!-- $I(s_1, c_1)$ -->\n",
       "    <g transform=\"translate(30.0550393701 95.2746825787)scale(0.11 -0.11)\">\n",
       "     <use transform=\"translate(0.0 0.40625)\" xlink:href=\"#STIXGeneral-Italic-1d610\"/>\n",
       "     <use transform=\"translate(40.09999084472656 0.40625)\" xlink:href=\"#STIXGeneral-Regular-28\"/>\n",
       "     <use transform=\"translate(73.39997863769531 0.40625)\" xlink:href=\"#STIXGeneral-Italic-1d634\"/>\n",
       "     <use transform=\"translate(112.29997253417969 -13.182812499999997)scale(0.7)\" xlink:href=\"#STIXGeneral-Regular-1d7e3\"/>\n",
       "     <use transform=\"translate(149.56480560302734 0.40625)\" xlink:href=\"#STIXGeneral-Regular-2c\"/>\n",
       "     <use transform=\"translate(189.6847885131836 0.40625)\" xlink:href=\"#STIXGeneral-Italic-1d624\"/>\n",
       "     <use transform=\"translate(235.28477935791017 -13.182812499999997)scale(0.7)\" xlink:href=\"#STIXGeneral-Regular-1d7e3\"/>\n",
       "     <use transform=\"translate(272.5496124267578 0.40625)\" xlink:href=\"#STIXGeneral-Regular-29\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"text_5\">\n",
       "    <!-- $G(s_1, c_2)$ -->\n",
       "    <g transform=\"translate(221.160944882 151.967595965)scale(0.11 -0.11)\">\n",
       "     <use transform=\"translate(0.0 0.40625)\" xlink:href=\"#STIXGeneral-Italic-1d60e\"/>\n",
       "     <use transform=\"translate(69.49998474121094 0.40625)\" xlink:href=\"#STIXGeneral-Regular-28\"/>\n",
       "     <use transform=\"translate(102.79997253417969 0.40625)\" xlink:href=\"#STIXGeneral-Italic-1d634\"/>\n",
       "     <use transform=\"translate(141.69996643066406 -13.182812499999997)scale(0.7)\" xlink:href=\"#STIXGeneral-Regular-1d7e3\"/>\n",
       "     <use transform=\"translate(178.9647994995117 0.40625)\" xlink:href=\"#STIXGeneral-Regular-2c\"/>\n",
       "     <use transform=\"translate(219.08478240966798 0.40625)\" xlink:href=\"#STIXGeneral-Italic-1d624\"/>\n",
       "     <use transform=\"translate(264.68477325439454 -13.182812499999997)scale(0.7)\" xlink:href=\"#STIXGeneral-Regular-1d7e4\"/>\n",
       "     <use transform=\"translate(301.94960632324216 0.40625)\" xlink:href=\"#STIXGeneral-Regular-29\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"text_6\">\n",
       "    <!-- $I(s_2, c_1)$ -->\n",
       "    <g transform=\"translate(143.440866142 95.2746825787)scale(0.11 -0.11)\">\n",
       "     <use transform=\"translate(0.0 0.40625)\" xlink:href=\"#STIXGeneral-Italic-1d610\"/>\n",
       "     <use transform=\"translate(40.09999084472656 0.40625)\" xlink:href=\"#STIXGeneral-Regular-28\"/>\n",
       "     <use transform=\"translate(73.39997863769531 0.40625)\" xlink:href=\"#STIXGeneral-Italic-1d634\"/>\n",
       "     <use transform=\"translate(112.29997253417969 -13.182812499999997)scale(0.7)\" xlink:href=\"#STIXGeneral-Regular-1d7e4\"/>\n",
       "     <use transform=\"translate(149.56480560302734 0.40625)\" xlink:href=\"#STIXGeneral-Regular-2c\"/>\n",
       "     <use transform=\"translate(189.6847885131836 0.40625)\" xlink:href=\"#STIXGeneral-Italic-1d624\"/>\n",
       "     <use transform=\"translate(235.28477935791017 -13.182812499999997)scale(0.7)\" xlink:href=\"#STIXGeneral-Regular-1d7e3\"/>\n",
       "     <use transform=\"translate(272.5496124267578 0.40625)\" xlink:href=\"#STIXGeneral-Regular-29\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"text_7\">\n",
       "    <!-- $G(s_1, c_1)$ -->\n",
       "    <g transform=\"translate(51.0822047244 151.967595965)scale(0.11 -0.11)\">\n",
       "     <use transform=\"translate(0.0 0.40625)\" xlink:href=\"#STIXGeneral-Italic-1d60e\"/>\n",
       "     <use transform=\"translate(69.49998474121094 0.40625)\" xlink:href=\"#STIXGeneral-Regular-28\"/>\n",
       "     <use transform=\"translate(102.79997253417969 0.40625)\" xlink:href=\"#STIXGeneral-Italic-1d634\"/>\n",
       "     <use transform=\"translate(141.69996643066406 -13.182812499999997)scale(0.7)\" xlink:href=\"#STIXGeneral-Regular-1d7e3\"/>\n",
       "     <use transform=\"translate(178.9647994995117 0.40625)\" xlink:href=\"#STIXGeneral-Regular-2c\"/>\n",
       "     <use transform=\"translate(219.08478240966798 0.40625)\" xlink:href=\"#STIXGeneral-Italic-1d624\"/>\n",
       "     <use transform=\"translate(264.68477325439454 -13.182812499999997)scale(0.7)\" xlink:href=\"#STIXGeneral-Regular-1d7e3\"/>\n",
       "     <use transform=\"translate(301.94960632324216 0.40625)\" xlink:href=\"#STIXGeneral-Regular-29\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"text_8\">\n",
       "    <!-- $I(s_1, c_2)$ -->\n",
       "    <g transform=\"translate(200.133779528 95.2746825787)scale(0.11 -0.11)\">\n",
       "     <use transform=\"translate(0.0 0.40625)\" xlink:href=\"#STIXGeneral-Italic-1d610\"/>\n",
       "     <use transform=\"translate(40.09999084472656 0.40625)\" xlink:href=\"#STIXGeneral-Regular-28\"/>\n",
       "     <use transform=\"translate(73.39997863769531 0.40625)\" xlink:href=\"#STIXGeneral-Italic-1d634\"/>\n",
       "     <use transform=\"translate(112.29997253417969 -13.182812499999997)scale(0.7)\" xlink:href=\"#STIXGeneral-Regular-1d7e3\"/>\n",
       "     <use transform=\"translate(149.56480560302734 0.40625)\" xlink:href=\"#STIXGeneral-Regular-2c\"/>\n",
       "     <use transform=\"translate(189.6847885131836 0.40625)\" xlink:href=\"#STIXGeneral-Italic-1d624\"/>\n",
       "     <use transform=\"translate(235.28477935791017 -13.182812499999997)scale(0.7)\" xlink:href=\"#STIXGeneral-Regular-1d7e4\"/>\n",
       "     <use transform=\"translate(272.5496124267578 0.40625)\" xlink:href=\"#STIXGeneral-Regular-29\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"text_9\">\n",
       "    <!-- $D(c_1)$ -->\n",
       "    <defs>\n",
       "     <path d=\"M 23.90625 66.203125 \n",
       "L 40.5 66.203125 \n",
       "Q 75.09375 66.203125 75.09375 42.90625 \n",
       "Q 75.09375 35.203125 72 27.640625 \n",
       "Q 68.90625 20.09375 63.25 13.890625 \n",
       "Q 57.59375 7.703125 48.640625 3.84375 \n",
       "Q 39.703125 0 28.90625 0 \n",
       "L 7.40625 0 \n",
       "z\n",
       "M 17.90625 7.40625 \n",
       "L 22.796875 7.40625 \n",
       "Q 32.203125 7.40625 37.5 8.15625 \n",
       "Q 42.796875 8.90625 48.203125 11.40625 \n",
       "Q 56.203125 15.09375 61.046875 23.140625 \n",
       "Q 65.90625 31.203125 65.90625 40.90625 \n",
       "Q 65.90625 58.796875 36.703125 58.796875 \n",
       "L 30.703125 58.796875 \n",
       "z\n",
       "\" id=\"STIXGeneral-Italic-1d60b\"/>\n",
       "    </defs>\n",
       "    <g transform=\"translate(90.4379527559 38.8577066929)scale(0.12 -0.12)\">\n",
       "     <use transform=\"translate(0.0 0.40625)\" xlink:href=\"#STIXGeneral-Italic-1d60b\"/>\n",
       "     <use transform=\"translate(69.19998168945312 0.40625)\" xlink:href=\"#STIXGeneral-Regular-28\"/>\n",
       "     <use transform=\"translate(102.49996948242188 0.40625)\" xlink:href=\"#STIXGeneral-Italic-1d624\"/>\n",
       "     <use transform=\"translate(148.09996032714844 -13.182812499999997)scale(0.7)\" xlink:href=\"#STIXGeneral-Regular-1d7e3\"/>\n",
       "     <use transform=\"translate(185.3647933959961 0.40625)\" xlink:href=\"#STIXGeneral-Regular-29\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"text_10\">\n",
       "    <!-- $D(c_2)$ -->\n",
       "    <g transform=\"translate(260.516692913 38.8577066929)scale(0.12 -0.12)\">\n",
       "     <use transform=\"translate(0.0 0.40625)\" xlink:href=\"#STIXGeneral-Italic-1d60b\"/>\n",
       "     <use transform=\"translate(69.19998168945312 0.40625)\" xlink:href=\"#STIXGeneral-Regular-28\"/>\n",
       "     <use transform=\"translate(102.49996948242188 0.40625)\" xlink:href=\"#STIXGeneral-Italic-1d624\"/>\n",
       "     <use transform=\"translate(148.09996032714844 -13.182812499999997)scale(0.7)\" xlink:href=\"#STIXGeneral-Regular-1d7e4\"/>\n",
       "     <use transform=\"translate(185.3647933959961 0.40625)\" xlink:href=\"#STIXGeneral-Regular-29\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "  </g>\n",
       " </g>\n",
       " <defs>\n",
       "  <clipPath id=\"pbf53d3b26e\">\n",
       "   <rect height=\"170.078740157\" width=\"340.157480315\" x=\"7.2\" y=\"7.2\"/>\n",
       "  </clipPath>\n",
       " </defs>\n",
       "</svg>\n"
      ],
      "text/plain": [
       "<matplotlib.figure.Figure at 0x7feb96c7bf98>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "pgm = daft.PGM([6, 3], origin=[-0.5, 0.5])\n",
    "add_node(pgm, 'Dc1', '$D(c_1)$', 1.2, 3, label_params={'size':12})\n",
    "add_node(pgm, 'Gs1c1', '$G(s_1, c_1)$', 0.6, 1, label_params={'size':11})\n",
    "add_node(pgm, 'Gs2c1', '$G(s_2, c_1)$', 1.8, 1, label_params={'size':11})\n",
    "add_node(pgm, 'Is1c1', '$I(s_1, c_1)$', 0.2, 2, label_params={'size':11})\n",
    "add_node(pgm, 'Is2c1', '$I(s_2, c_1)$', 2.2, 2, label_params={'size':11})\n",
    "add_node(pgm, 'Dc2', '$D(c_2)$', 4.2, 3, label_params={'size':12})\n",
    "add_node(pgm, 'Gs1c2', '$G(s_1, c_2)$', 3.6, 1, label_params={'size':11})\n",
    "add_node(pgm, 'Gs2c2', '$G(s_2, c_2)$', 4.8, 1, label_params={'size':11})\n",
    "add_node(pgm, 'Is1c2', '$I(s_1, c_2)$', 3.2, 2, label_params={'size':11})\n",
    "add_node(pgm, 'Is2c2', '$I(s_2, c_2)$', 5.2, 2, label_params={'size':11})\n",
    "add_edges(pgm, [\n",
    "        ('Dc1', 'Gs1c1'),\n",
    "        ('Is1c1', 'Gs1c1'),\n",
    "        ('Dc1', 'Gs2c1'),\n",
    "        ('Is2c1', 'Gs2c1'),\n",
    "        ('Dc2', 'Gs1c2'),\n",
    "        ('Is1c2', 'Gs1c2'),\n",
    "        ('Dc2', 'Gs2c2'),\n",
    "        ('Is2c2', 'Gs2c2')\n",
    "    ])\n",
    "pgm.render()\n",
    "save('bn_plate_model_02_unrolled')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "image/svg+xml": [
       "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"no\"?>\n",
       "<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\n",
       "  \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n",
       "<!-- Created with matplotlib (http://matplotlib.org/) -->\n",
       "<svg height=\"127pt\" version=\"1.1\" viewBox=\"0 0 156 127\" width=\"156pt\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n",
       " <defs>\n",
       "  <style type=\"text/css\">\n",
       "*{stroke-linecap:butt;stroke-linejoin:round;stroke-miterlimit:100000;}\n",
       "  </style>\n",
       " </defs>\n",
       " <g id=\"figure_1\">\n",
       "  <g id=\"patch_1\">\n",
       "   <path d=\"M 0 127.785827 \n",
       "L 156.132283 127.785827 \n",
       "L 156.132283 0 \n",
       "L 0 0 \n",
       "L 0 127.785827 \n",
       "z\n",
       "\" style=\"fill:none;\"/>\n",
       "  </g>\n",
       "  <g id=\"axes_1\">\n",
       "   <g id=\"patch_2\">\n",
       "    <path clip-path=\"url(#p1dd510ce43)\" d=\"M 68.874404 68.874404 \n",
       "L 65.366709 68.373305 \n",
       "L 66.870007 66.870007 \n",
       "L 47.57284 47.57284 \n",
       "L 47.57284 47.57284 \n",
       "L 66.870007 66.870007 \n",
       "L 68.373305 65.366709 \n",
       "L 68.874404 68.874404 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_3\">\n",
       "    <path clip-path=\"url(#p1dd510ce43)\" d=\"M 80.900787 63.892913 \n",
       "L 78.774803 61.058268 \n",
       "L 80.900787 61.058268 \n",
       "L 80.900787 52.554331 \n",
       "L 80.900787 52.554331 \n",
       "L 80.900787 61.058268 \n",
       "L 83.026772 61.058268 \n",
       "L 80.900787 63.892913 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_4\">\n",
       "    <path clip-path=\"url(#p1dd510ce43)\" d=\"M 92.92717 68.874404 \n",
       "L 93.42827 65.366709 \n",
       "L 94.931568 66.870007 \n",
       "L 114.228735 47.57284 \n",
       "L 114.228735 47.57284 \n",
       "L 94.931568 66.870007 \n",
       "L 96.434866 68.373305 \n",
       "L 92.92717 68.874404 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_5\">\n",
       "    <path clip-path=\"url(#p1dd510ce43)\" d=\"M 35.546457 52.554331 \n",
       "C 40.056998 52.554331 44.383406 50.762274 47.57284 47.57284 \n",
       "C 50.762274 44.383406 52.554331 40.056998 52.554331 35.546457 \n",
       "C 52.554331 31.035916 50.762274 26.709508 47.57284 23.520074 \n",
       "C 44.383406 20.33064 40.056998 18.538583 35.546457 18.538583 \n",
       "C 31.035916 18.538583 26.709508 20.33064 23.520074 23.520074 \n",
       "C 20.33064 26.709508 18.538583 31.035916 18.538583 35.546457 \n",
       "C 18.538583 40.056998 20.33064 44.383406 23.520074 47.57284 \n",
       "C 26.709508 50.762274 31.035916 52.554331 35.546457 52.554331 \n",
       "L 35.546457 52.554331 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_6\">\n",
       "    <path clip-path=\"url(#p1dd510ce43)\" d=\"M 80.900787 52.554331 \n",
       "C 85.411328 52.554331 89.737736 50.762274 92.92717 47.57284 \n",
       "C 96.116605 44.383406 97.908661 40.056998 97.908661 35.546457 \n",
       "C 97.908661 31.035916 96.116605 26.709508 92.92717 23.520074 \n",
       "C 89.737736 20.33064 85.411328 18.538583 80.900787 18.538583 \n",
       "C 76.390246 18.538583 72.063838 20.33064 68.874404 23.520074 \n",
       "C 65.68497 26.709508 63.892913 31.035916 63.892913 35.546457 \n",
       "C 63.892913 40.056998 65.68497 44.383406 68.874404 47.57284 \n",
       "C 72.063838 50.762274 76.390246 52.554331 80.900787 52.554331 \n",
       "L 80.900787 52.554331 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_7\">\n",
       "    <path clip-path=\"url(#p1dd510ce43)\" d=\"M 80.900787 97.908661 \n",
       "C 85.411328 97.908661 89.737736 96.116605 92.92717 92.92717 \n",
       "C 96.116605 89.737736 97.908661 85.411328 97.908661 80.900787 \n",
       "C 97.908661 76.390246 96.116605 72.063838 92.92717 68.874404 \n",
       "C 89.737736 65.68497 85.411328 63.892913 80.900787 63.892913 \n",
       "C 76.390246 63.892913 72.063838 65.68497 68.874404 68.874404 \n",
       "C 65.68497 72.063838 63.892913 76.390246 63.892913 80.900787 \n",
       "C 63.892913 85.411328 65.68497 89.737736 68.874404 92.92717 \n",
       "C 72.063838 96.116605 76.390246 97.908661 80.900787 97.908661 \n",
       "L 80.900787 97.908661 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_8\">\n",
       "    <path clip-path=\"url(#p1dd510ce43)\" d=\"M 126.255118 52.554331 \n",
       "C 130.765659 52.554331 135.092067 50.762274 138.281501 47.57284 \n",
       "C 141.470935 44.383406 143.262992 40.056998 143.262992 35.546457 \n",
       "C 143.262992 31.035916 141.470935 26.709508 138.281501 23.520074 \n",
       "C 135.092067 20.33064 130.765659 18.538583 126.255118 18.538583 \n",
       "C 121.744577 18.538583 117.418169 20.33064 114.228735 23.520074 \n",
       "C 111.039301 26.709508 109.247244 31.035916 109.247244 35.546457 \n",
       "C 109.247244 40.056998 111.039301 44.383406 114.228735 47.57284 \n",
       "C 117.418169 50.762274 121.744577 52.554331 126.255118 52.554331 \n",
       "L 126.255118 52.554331 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"matplotlib.axis_1\"/>\n",
       "   <g id=\"matplotlib.axis_2\"/>\n",
       "   <g id=\"text_1\">\n",
       "    <!-- apply -->\n",
       "    <defs>\n",
       "     <path d=\"M 18.109375 8.203125 \n",
       "L 18.109375 -20.796875 \n",
       "L 9.078125 -20.796875 \n",
       "L 9.078125 54.6875 \n",
       "L 18.109375 54.6875 \n",
       "L 18.109375 46.390625 \n",
       "Q 20.953125 51.265625 25.265625 53.625 \n",
       "Q 29.59375 56 35.59375 56 \n",
       "Q 45.5625 56 51.78125 48.09375 \n",
       "Q 58.015625 40.1875 58.015625 27.296875 \n",
       "Q 58.015625 14.40625 51.78125 6.484375 \n",
       "Q 45.5625 -1.421875 35.59375 -1.421875 \n",
       "Q 29.59375 -1.421875 25.265625 0.953125 \n",
       "Q 20.953125 3.328125 18.109375 8.203125 \n",
       "M 48.6875 27.296875 \n",
       "Q 48.6875 37.203125 44.609375 42.84375 \n",
       "Q 40.53125 48.484375 33.40625 48.484375 \n",
       "Q 26.265625 48.484375 22.1875 42.84375 \n",
       "Q 18.109375 37.203125 18.109375 27.296875 \n",
       "Q 18.109375 17.390625 22.1875 11.75 \n",
       "Q 26.265625 6.109375 33.40625 6.109375 \n",
       "Q 40.53125 6.109375 44.609375 11.75 \n",
       "Q 48.6875 17.390625 48.6875 27.296875 \n",
       "\" id=\"BitstreamVeraSans-Roman-70\"/>\n",
       "     <path d=\"M 34.28125 27.484375 \n",
       "Q 23.390625 27.484375 19.1875 25 \n",
       "Q 14.984375 22.515625 14.984375 16.5 \n",
       "Q 14.984375 11.71875 18.140625 8.90625 \n",
       "Q 21.296875 6.109375 26.703125 6.109375 \n",
       "Q 34.1875 6.109375 38.703125 11.40625 \n",
       "Q 43.21875 16.703125 43.21875 25.484375 \n",
       "L 43.21875 27.484375 \n",
       "z\n",
       "M 52.203125 31.203125 \n",
       "L 52.203125 0 \n",
       "L 43.21875 0 \n",
       "L 43.21875 8.296875 \n",
       "Q 40.140625 3.328125 35.546875 0.953125 \n",
       "Q 30.953125 -1.421875 24.3125 -1.421875 \n",
       "Q 15.921875 -1.421875 10.953125 3.296875 \n",
       "Q 6 8.015625 6 15.921875 \n",
       "Q 6 25.140625 12.171875 29.828125 \n",
       "Q 18.359375 34.515625 30.609375 34.515625 \n",
       "L 43.21875 34.515625 \n",
       "L 43.21875 35.40625 \n",
       "Q 43.21875 41.609375 39.140625 45 \n",
       "Q 35.0625 48.390625 27.6875 48.390625 \n",
       "Q 23 48.390625 18.546875 47.265625 \n",
       "Q 14.109375 46.140625 10.015625 43.890625 \n",
       "L 10.015625 52.203125 \n",
       "Q 14.9375 54.109375 19.578125 55.046875 \n",
       "Q 24.21875 56 28.609375 56 \n",
       "Q 40.484375 56 46.34375 49.84375 \n",
       "Q 52.203125 43.703125 52.203125 31.203125 \n",
       "\" id=\"BitstreamVeraSans-Roman-61\"/>\n",
       "     <path d=\"M 9.421875 75.984375 \n",
       "L 18.40625 75.984375 \n",
       "L 18.40625 0 \n",
       "L 9.421875 0 \n",
       "z\n",
       "\" id=\"BitstreamVeraSans-Roman-6c\"/>\n",
       "     <path d=\"M 32.171875 -5.078125 \n",
       "Q 28.375 -14.84375 24.75 -17.8125 \n",
       "Q 21.140625 -20.796875 15.09375 -20.796875 \n",
       "L 7.90625 -20.796875 \n",
       "L 7.90625 -13.28125 \n",
       "L 13.1875 -13.28125 \n",
       "Q 16.890625 -13.28125 18.9375 -11.515625 \n",
       "Q 21 -9.765625 23.484375 -3.21875 \n",
       "L 25.09375 0.875 \n",
       "L 2.984375 54.6875 \n",
       "L 12.5 54.6875 \n",
       "L 29.59375 11.921875 \n",
       "L 46.6875 54.6875 \n",
       "L 56.203125 54.6875 \n",
       "z\n",
       "\" id=\"BitstreamVeraSans-Roman-79\"/>\n",
       "    </defs>\n",
       "    <g transform=\"translate(20.4094254429 38.5817691929)scale(0.11 -0.11)\">\n",
       "     <use xlink:href=\"#BitstreamVeraSans-Roman-61\"/>\n",
       "     <use x=\"61.279296875\" xlink:href=\"#BitstreamVeraSans-Roman-70\"/>\n",
       "     <use x=\"124.755859375\" xlink:href=\"#BitstreamVeraSans-Roman-70\"/>\n",
       "     <use x=\"188.232421875\" xlink:href=\"#BitstreamVeraSans-Roman-6c\"/>\n",
       "     <use x=\"216.015625\" xlink:href=\"#BitstreamVeraSans-Roman-79\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"text_2\">\n",
       "    <!-- letter -->\n",
       "    <defs>\n",
       "     <path d=\"M 18.3125 70.21875 \n",
       "L 18.3125 54.6875 \n",
       "L 36.8125 54.6875 \n",
       "L 36.8125 47.703125 \n",
       "L 18.3125 47.703125 \n",
       "L 18.3125 18.015625 \n",
       "Q 18.3125 11.328125 20.140625 9.421875 \n",
       "Q 21.96875 7.515625 27.59375 7.515625 \n",
       "L 36.8125 7.515625 \n",
       "L 36.8125 0 \n",
       "L 27.59375 0 \n",
       "Q 17.1875 0 13.234375 3.875 \n",
       "Q 9.28125 7.765625 9.28125 18.015625 \n",
       "L 9.28125 47.703125 \n",
       "L 2.6875 47.703125 \n",
       "L 2.6875 54.6875 \n",
       "L 9.28125 54.6875 \n",
       "L 9.28125 70.21875 \n",
       "z\n",
       "\" id=\"BitstreamVeraSans-Roman-74\"/>\n",
       "     <path d=\"M 56.203125 29.59375 \n",
       "L 56.203125 25.203125 \n",
       "L 14.890625 25.203125 \n",
       "Q 15.484375 15.921875 20.484375 11.0625 \n",
       "Q 25.484375 6.203125 34.421875 6.203125 \n",
       "Q 39.59375 6.203125 44.453125 7.46875 \n",
       "Q 49.3125 8.734375 54.109375 11.28125 \n",
       "L 54.109375 2.78125 \n",
       "Q 49.265625 0.734375 44.1875 -0.34375 \n",
       "Q 39.109375 -1.421875 33.890625 -1.421875 \n",
       "Q 20.796875 -1.421875 13.15625 6.1875 \n",
       "Q 5.515625 13.8125 5.515625 26.8125 \n",
       "Q 5.515625 40.234375 12.765625 48.109375 \n",
       "Q 20.015625 56 32.328125 56 \n",
       "Q 43.359375 56 49.78125 48.890625 \n",
       "Q 56.203125 41.796875 56.203125 29.59375 \n",
       "M 47.21875 32.234375 \n",
       "Q 47.125 39.59375 43.09375 43.984375 \n",
       "Q 39.0625 48.390625 32.421875 48.390625 \n",
       "Q 24.90625 48.390625 20.390625 44.140625 \n",
       "Q 15.875 39.890625 15.1875 32.171875 \n",
       "z\n",
       "\" id=\"BitstreamVeraSans-Roman-65\"/>\n",
       "     <path d=\"M 41.109375 46.296875 \n",
       "Q 39.59375 47.171875 37.8125 47.578125 \n",
       "Q 36.03125 48 33.890625 48 \n",
       "Q 26.265625 48 22.1875 43.046875 \n",
       "Q 18.109375 38.09375 18.109375 28.8125 \n",
       "L 18.109375 0 \n",
       "L 9.078125 0 \n",
       "L 9.078125 54.6875 \n",
       "L 18.109375 54.6875 \n",
       "L 18.109375 46.1875 \n",
       "Q 20.953125 51.171875 25.484375 53.578125 \n",
       "Q 30.03125 56 36.53125 56 \n",
       "Q 37.453125 56 38.578125 55.875 \n",
       "Q 39.703125 55.765625 41.0625 55.515625 \n",
       "z\n",
       "\" id=\"BitstreamVeraSans-Roman-72\"/>\n",
       "    </defs>\n",
       "    <g transform=\"translate(66.0310217766 38.5817691929)scale(0.11 -0.11)\">\n",
       "     <use xlink:href=\"#BitstreamVeraSans-Roman-6c\"/>\n",
       "     <use x=\"27.783203125\" xlink:href=\"#BitstreamVeraSans-Roman-65\"/>\n",
       "     <use x=\"89.306640625\" xlink:href=\"#BitstreamVeraSans-Roman-74\"/>\n",
       "     <use x=\"128.515625\" xlink:href=\"#BitstreamVeraSans-Roman-74\"/>\n",
       "     <use x=\"167.724609375\" xlink:href=\"#BitstreamVeraSans-Roman-65\"/>\n",
       "     <use x=\"229.248046875\" xlink:href=\"#BitstreamVeraSans-Roman-72\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"text_3\">\n",
       "    <!-- job -->\n",
       "    <defs>\n",
       "     <path d=\"M 9.421875 54.6875 \n",
       "L 18.40625 54.6875 \n",
       "L 18.40625 -0.984375 \n",
       "Q 18.40625 -11.421875 14.421875 -16.109375 \n",
       "Q 10.453125 -20.796875 1.609375 -20.796875 \n",
       "L -1.8125 -20.796875 \n",
       "L -1.8125 -13.1875 \n",
       "L 0.59375 -13.1875 \n",
       "Q 5.71875 -13.1875 7.5625 -10.8125 \n",
       "Q 9.421875 -8.453125 9.421875 -0.984375 \n",
       "z\n",
       "M 9.421875 75.984375 \n",
       "L 18.40625 75.984375 \n",
       "L 18.40625 64.59375 \n",
       "L 9.421875 64.59375 \n",
       "z\n",
       "\" id=\"BitstreamVeraSans-Roman-6a\"/>\n",
       "     <path d=\"M 48.6875 27.296875 \n",
       "Q 48.6875 37.203125 44.609375 42.84375 \n",
       "Q 40.53125 48.484375 33.40625 48.484375 \n",
       "Q 26.265625 48.484375 22.1875 42.84375 \n",
       "Q 18.109375 37.203125 18.109375 27.296875 \n",
       "Q 18.109375 17.390625 22.1875 11.75 \n",
       "Q 26.265625 6.109375 33.40625 6.109375 \n",
       "Q 40.53125 6.109375 44.609375 11.75 \n",
       "Q 48.6875 17.390625 48.6875 27.296875 \n",
       "M 18.109375 46.390625 \n",
       "Q 20.953125 51.265625 25.265625 53.625 \n",
       "Q 29.59375 56 35.59375 56 \n",
       "Q 45.5625 56 51.78125 48.09375 \n",
       "Q 58.015625 40.1875 58.015625 27.296875 \n",
       "Q 58.015625 14.40625 51.78125 6.484375 \n",
       "Q 45.5625 -1.421875 35.59375 -1.421875 \n",
       "Q 29.59375 -1.421875 25.265625 0.953125 \n",
       "Q 20.953125 3.328125 18.109375 8.203125 \n",
       "L 18.109375 0 \n",
       "L 9.078125 0 \n",
       "L 9.078125 75.984375 \n",
       "L 18.109375 75.984375 \n",
       "z\n",
       "\" id=\"BitstreamVeraSans-Roman-62\"/>\n",
       "     <path d=\"M 30.609375 48.390625 \n",
       "Q 23.390625 48.390625 19.1875 42.75 \n",
       "Q 14.984375 37.109375 14.984375 27.296875 \n",
       "Q 14.984375 17.484375 19.15625 11.84375 \n",
       "Q 23.34375 6.203125 30.609375 6.203125 \n",
       "Q 37.796875 6.203125 41.984375 11.859375 \n",
       "Q 46.1875 17.53125 46.1875 27.296875 \n",
       "Q 46.1875 37.015625 41.984375 42.703125 \n",
       "Q 37.796875 48.390625 30.609375 48.390625 \n",
       "M 30.609375 56 \n",
       "Q 42.328125 56 49.015625 48.375 \n",
       "Q 55.71875 40.765625 55.71875 27.296875 \n",
       "Q 55.71875 13.875 49.015625 6.21875 \n",
       "Q 42.328125 -1.421875 30.609375 -1.421875 \n",
       "Q 18.84375 -1.421875 12.171875 6.21875 \n",
       "Q 5.515625 13.875 5.515625 27.296875 \n",
       "Q 5.515625 40.765625 12.171875 48.375 \n",
       "Q 18.84375 56 30.609375 56 \n",
       "\" id=\"BitstreamVeraSans-Roman-6f\"/>\n",
       "    </defs>\n",
       "    <g transform=\"translate(72.5158655266 83.9360999016)scale(0.11 -0.11)\">\n",
       "     <use xlink:href=\"#BitstreamVeraSans-Roman-6a\"/>\n",
       "     <use x=\"27.783203125\" xlink:href=\"#BitstreamVeraSans-Roman-6f\"/>\n",
       "     <use x=\"88.96484375\" xlink:href=\"#BitstreamVeraSans-Roman-62\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"text_4\">\n",
       "    <!-- SAT -->\n",
       "    <defs>\n",
       "     <path d=\"M 53.515625 70.515625 \n",
       "L 53.515625 60.890625 \n",
       "Q 47.90625 63.578125 42.921875 64.890625 \n",
       "Q 37.9375 66.21875 33.296875 66.21875 \n",
       "Q 25.25 66.21875 20.875 63.09375 \n",
       "Q 16.5 59.96875 16.5 54.203125 \n",
       "Q 16.5 49.359375 19.40625 46.890625 \n",
       "Q 22.3125 44.4375 30.421875 42.921875 \n",
       "L 36.375 41.703125 \n",
       "Q 47.40625 39.59375 52.65625 34.296875 \n",
       "Q 57.90625 29 57.90625 20.125 \n",
       "Q 57.90625 9.515625 50.796875 4.046875 \n",
       "Q 43.703125 -1.421875 29.984375 -1.421875 \n",
       "Q 24.8125 -1.421875 18.96875 -0.25 \n",
       "Q 13.140625 0.921875 6.890625 3.21875 \n",
       "L 6.890625 13.375 \n",
       "Q 12.890625 10.015625 18.65625 8.296875 \n",
       "Q 24.421875 6.59375 29.984375 6.59375 \n",
       "Q 38.421875 6.59375 43.015625 9.90625 \n",
       "Q 47.609375 13.234375 47.609375 19.390625 \n",
       "Q 47.609375 24.75 44.3125 27.78125 \n",
       "Q 41.015625 30.8125 33.5 32.328125 \n",
       "L 27.484375 33.5 \n",
       "Q 16.453125 35.6875 11.515625 40.375 \n",
       "Q 6.59375 45.0625 6.59375 53.421875 \n",
       "Q 6.59375 63.09375 13.40625 68.65625 \n",
       "Q 20.21875 74.21875 32.171875 74.21875 \n",
       "Q 37.3125 74.21875 42.625 73.28125 \n",
       "Q 47.953125 72.359375 53.515625 70.515625 \n",
       "\" id=\"BitstreamVeraSans-Roman-53\"/>\n",
       "     <path d=\"M -0.296875 72.90625 \n",
       "L 61.375 72.90625 \n",
       "L 61.375 64.59375 \n",
       "L 35.5 64.59375 \n",
       "L 35.5 0 \n",
       "L 25.59375 0 \n",
       "L 25.59375 64.59375 \n",
       "L -0.296875 64.59375 \n",
       "z\n",
       "\" id=\"BitstreamVeraSans-Roman-54\"/>\n",
       "     <path d=\"M 34.1875 63.1875 \n",
       "L 20.796875 26.90625 \n",
       "L 47.609375 26.90625 \n",
       "z\n",
       "M 28.609375 72.90625 \n",
       "L 39.796875 72.90625 \n",
       "L 67.578125 0 \n",
       "L 57.328125 0 \n",
       "L 50.6875 18.703125 \n",
       "L 17.828125 18.703125 \n",
       "L 11.1875 0 \n",
       "L 0.78125 0 \n",
       "z\n",
       "\" id=\"BitstreamVeraSans-Roman-41\"/>\n",
       "    </defs>\n",
       "    <g transform=\"translate(115.64699311 38.5817691929)scale(0.11 -0.11)\">\n",
       "     <use xlink:href=\"#BitstreamVeraSans-Roman-53\"/>\n",
       "     <use x=\"63.4921875\" xlink:href=\"#BitstreamVeraSans-Roman-41\"/>\n",
       "     <use x=\"131.791015625\" xlink:href=\"#BitstreamVeraSans-Roman-54\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "  </g>\n",
       " </g>\n",
       " <defs>\n",
       "  <clipPath id=\"p1dd510ce43\">\n",
       "   <rect height=\"113.385826772\" width=\"141.732283465\" x=\"7.2\" y=\"7.2\"/>\n",
       "  </clipPath>\n",
       " </defs>\n",
       "</svg>\n"
      ],
      "text/plain": [
       "<matplotlib.figure.Figure at 0x7feb96c7b128>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "pgm = daft.PGM([2.5, 2], origin=[-0.5, 0.5])\n",
    "add_node(pgm, 'a', 'apply', 0, 2, label_params={'size':11})\n",
    "add_node(pgm, 'j', 'job', 0.8, 1.2, label_params={'size':11})\n",
    "add_node(pgm, 'l', 'letter', 0.8, 2, label_params={'size':11})\n",
    "add_node(pgm, 's', 'SAT', 1.6, 2, label_params={'size':11})\n",
    "add_edges(pgm, [\n",
    "        ('a', 'j'),\n",
    "        ('l', 'j'),\n",
    "        ('s', 'j')\n",
    "    ])\n",
    "pgm.render()\n",
    "save('bn_tree_cpd_00')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "image/svg+xml": [
       "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"no\"?>\n",
       "<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\n",
       "  \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n",
       "<!-- Created with matplotlib (http://matplotlib.org/) -->\n",
       "<svg height=\"241pt\" version=\"1.1\" viewBox=\"0 0 247 241\" width=\"247pt\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n",
       " <defs>\n",
       "  <style type=\"text/css\">\n",
       "*{stroke-linecap:butt;stroke-linejoin:round;stroke-miterlimit:100000;}\n",
       "  </style>\n",
       " </defs>\n",
       " <g id=\"figure_1\">\n",
       "  <g id=\"patch_1\">\n",
       "   <path d=\"M 0 241.171654 \n",
       "L 247.655197 241.171654 \n",
       "L 247.655197 -0 \n",
       "L 0 -0 \n",
       "L 0 241.171654 \n",
       "z\n",
       "\" style=\"fill:none;\"/>\n",
       "  </g>\n",
       "  <g id=\"axes_1\">\n",
       "   <g id=\"patch_2\">\n",
       "    <path clip-path=\"url(#p93cbb209c9)\" d=\"M 122.113927 78.958452 \n",
       "L 118.683023 78.073057 \n",
       "L 120.343138 76.744965 \n",
       "L 98.009065 48.827375 \n",
       "L 98.009065 48.827375 \n",
       "L 120.343138 76.744965 \n",
       "L 122.003252 75.416874 \n",
       "L 122.113927 78.958452 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_3\">\n",
       "    <path clip-path=\"url(#p93cbb209c9)\" d=\"M 98.009065 135.651365 \n",
       "L 98.11974 132.109787 \n",
       "L 99.779854 133.437879 \n",
       "L 122.113927 105.520288 \n",
       "L 122.113927 105.520288 \n",
       "L 99.779854 133.437879 \n",
       "L 101.439969 134.765971 \n",
       "L 98.009065 135.651365 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_4\">\n",
       "    <path clip-path=\"url(#p93cbb209c9)\" d=\"M 52.654735 78.958452 \n",
       "L 52.765409 75.416874 \n",
       "L 54.425524 76.744965 \n",
       "L 76.759596 48.827375 \n",
       "L 76.759596 48.827375 \n",
       "L 54.425524 76.744965 \n",
       "L 56.085639 78.073057 \n",
       "L 52.654735 78.958452 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_5\">\n",
       "    <path clip-path=\"url(#p93cbb209c9)\" d=\"M 167.468257 135.651365 \n",
       "L 164.037354 134.765971 \n",
       "L 165.697468 133.437879 \n",
       "L 143.363396 105.520288 \n",
       "L 143.363396 105.520288 \n",
       "L 165.697468 133.437879 \n",
       "L 167.357583 132.109787 \n",
       "L 167.468257 135.651365 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_6\">\n",
       "    <path clip-path=\"url(#p93cbb209c9)\" d=\"M 52.654735 192.344279 \n",
       "L 52.765409 188.8027 \n",
       "L 54.425524 190.130792 \n",
       "L 76.759596 162.213202 \n",
       "L 76.759596 162.213202 \n",
       "L 54.425524 190.130792 \n",
       "L 56.085639 191.458884 \n",
       "L 52.654735 192.344279 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_7\">\n",
       "    <path clip-path=\"url(#p93cbb209c9)\" d=\"M 122.113927 192.344279 \n",
       "L 118.683023 191.458884 \n",
       "L 120.343138 190.130792 \n",
       "L 98.009065 162.213202 \n",
       "L 98.009065 162.213202 \n",
       "L 120.343138 190.130792 \n",
       "L 122.003252 188.8027 \n",
       "L 122.113927 192.344279 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_8\">\n",
       "    <path clip-path=\"url(#p93cbb209c9)\" d=\"M 87.384331 52.554331 \n",
       "C 91.894872 52.554331 96.22128 50.762274 99.410714 47.57284 \n",
       "C 102.600148 44.383406 104.392205 40.056998 104.392205 35.546457 \n",
       "C 104.392205 31.035916 102.600148 26.709508 99.410714 23.520074 \n",
       "C 96.22128 20.33064 91.894872 18.538583 87.384331 18.538583 \n",
       "C 82.87379 18.538583 78.547382 20.33064 75.357948 23.520074 \n",
       "C 72.168514 26.709508 70.376457 31.035916 70.376457 35.546457 \n",
       "C 70.376457 40.056998 72.168514 44.383406 75.357948 47.57284 \n",
       "C 78.547382 50.762274 82.87379 52.554331 87.384331 52.554331 \n",
       "L 87.384331 52.554331 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_9\">\n",
       "    <path clip-path=\"url(#p93cbb209c9)\" d=\"M 87.384331 165.940157 \n",
       "C 91.894872 165.940157 96.22128 164.148101 99.410714 160.958667 \n",
       "C 102.600148 157.769232 104.392205 153.442824 104.392205 148.932283 \n",
       "C 104.392205 144.421743 102.600148 140.095334 99.410714 136.9059 \n",
       "C 96.22128 133.716466 91.894872 131.924409 87.384331 131.924409 \n",
       "C 82.87379 131.924409 78.547382 133.716466 75.357948 136.9059 \n",
       "C 72.168514 140.095334 70.376457 144.421743 70.376457 148.932283 \n",
       "C 70.376457 153.442824 72.168514 157.769232 75.357948 160.958667 \n",
       "C 78.547382 164.148101 82.87379 165.940157 87.384331 165.940157 \n",
       "L 87.384331 165.940157 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_10\">\n",
       "    <path clip-path=\"url(#p93cbb209c9)\" d=\"M 42.03 109.247244 \n",
       "C 46.540541 109.247244 50.866949 107.455187 54.056383 104.265753 \n",
       "C 57.245817 101.076319 59.037874 96.749911 59.037874 92.23937 \n",
       "C 59.037874 87.728829 57.245817 83.402421 54.056383 80.212987 \n",
       "C 50.866949 77.023553 46.540541 75.231496 42.03 75.231496 \n",
       "C 37.519459 75.231496 33.193051 77.023553 30.003617 80.212987 \n",
       "C 26.814183 83.402421 25.022126 87.728829 25.022126 92.23937 \n",
       "C 25.022126 96.749911 26.814183 101.076319 30.003617 104.265753 \n",
       "C 33.193051 107.455187 37.519459 109.247244 42.03 109.247244 \n",
       "L 42.03 109.247244 \n",
       "z\n",
       "\" style=\"fill:none;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_11\">\n",
       "    <path clip-path=\"url(#p93cbb209c9)\" d=\"M 132.738661 109.247244 \n",
       "C 137.249202 109.247244 141.57561 107.455187 144.765044 104.265753 \n",
       "C 147.954479 101.076319 149.746535 96.749911 149.746535 92.23937 \n",
       "C 149.746535 87.728829 147.954479 83.402421 144.765044 80.212987 \n",
       "C 141.57561 77.023553 137.249202 75.231496 132.738661 75.231496 \n",
       "C 128.228121 75.231496 123.901712 77.023553 120.712278 80.212987 \n",
       "C 117.522844 83.402421 115.730787 87.728829 115.730787 92.23937 \n",
       "C 115.730787 96.749911 117.522844 101.076319 120.712278 104.265753 \n",
       "C 123.901712 107.455187 128.228121 109.247244 132.738661 109.247244 \n",
       "L 132.738661 109.247244 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_12\">\n",
       "    <path clip-path=\"url(#p93cbb209c9)\" d=\"M 42.03 222.633071 \n",
       "C 46.540541 222.633071 50.866949 220.841014 54.056383 217.65158 \n",
       "C 57.245817 214.462146 59.037874 210.135738 59.037874 205.625197 \n",
       "C 59.037874 201.114656 57.245817 196.788248 54.056383 193.598814 \n",
       "C 50.866949 190.40938 46.540541 188.617323 42.03 188.617323 \n",
       "C 37.519459 188.617323 33.193051 190.40938 30.003617 193.598814 \n",
       "C 26.814183 196.788248 25.022126 201.114656 25.022126 205.625197 \n",
       "C 25.022126 210.135738 26.814183 214.462146 30.003617 217.65158 \n",
       "C 33.193051 220.841014 37.519459 222.633071 42.03 222.633071 \n",
       "L 42.03 222.633071 \n",
       "z\n",
       "\" style=\"fill:none;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_13\">\n",
       "    <path clip-path=\"url(#p93cbb209c9)\" d=\"M 178.092992 165.940157 \n",
       "C 182.603533 165.940157 186.929941 164.148101 190.119375 160.958667 \n",
       "C 193.308809 157.769232 195.100866 153.442824 195.100866 148.932283 \n",
       "C 195.100866 144.421743 193.308809 140.095334 190.119375 136.9059 \n",
       "C 186.929941 133.716466 182.603533 131.924409 178.092992 131.924409 \n",
       "C 173.582451 131.924409 169.256043 133.716466 166.066609 136.9059 \n",
       "C 162.877175 140.095334 161.085118 144.421743 161.085118 148.932283 \n",
       "C 161.085118 153.442824 162.877175 157.769232 166.066609 160.958667 \n",
       "C 169.256043 164.148101 173.582451 165.940157 178.092992 165.940157 \n",
       "L 178.092992 165.940157 \n",
       "z\n",
       "\" style=\"fill:none;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_14\">\n",
       "    <path clip-path=\"url(#p93cbb209c9)\" d=\"M 132.738661 222.633071 \n",
       "C 137.249202 222.633071 141.57561 220.841014 144.765044 217.65158 \n",
       "C 147.954479 214.462146 149.746535 210.135738 149.746535 205.625197 \n",
       "C 149.746535 201.114656 147.954479 196.788248 144.765044 193.598814 \n",
       "C 141.57561 190.40938 137.249202 188.617323 132.738661 188.617323 \n",
       "C 128.228121 188.617323 123.901712 190.40938 120.712278 193.598814 \n",
       "C 117.522844 196.788248 115.730787 201.114656 115.730787 205.625197 \n",
       "C 115.730787 210.135738 117.522844 214.462146 120.712278 217.65158 \n",
       "C 123.901712 220.841014 128.228121 222.633071 132.738661 222.633071 \n",
       "L 132.738661 222.633071 \n",
       "z\n",
       "\" style=\"fill:none;\"/>\n",
       "   </g>\n",
       "   <g id=\"matplotlib.axis_1\"/>\n",
       "   <g id=\"matplotlib.axis_2\"/>\n",
       "   <g id=\"text_1\">\n",
       "    <!-- $+a$ -->\n",
       "    <defs>\n",
       "     <path d=\"M 63.59375 22 \n",
       "L 37.5 22 \n",
       "L 37.5 -4.09375 \n",
       "L 30.90625 -4.09375 \n",
       "L 30.90625 22 \n",
       "L 4.796875 22 \n",
       "L 4.796875 28.59375 \n",
       "L 30.90625 28.59375 \n",
       "L 30.90625 54.703125 \n",
       "L 37.5 54.703125 \n",
       "L 37.5 28.59375 \n",
       "L 63.59375 28.59375 \n",
       "z\n",
       "\" id=\"STIXGeneral-Regular-2b\"/>\n",
       "     <path d=\"M 16.90625 30.203125 \n",
       "L 12.796875 33.296875 \n",
       "Q 15.796875 40.09375 21.34375 43.1875 \n",
       "Q 26.90625 46.296875 33.40625 46.296875 \n",
       "Q 39.703125 46.296875 43.203125 43.640625 \n",
       "Q 46.703125 41 46.703125 36.203125 \n",
       "Q 46.703125 34.796875 46.203125 32.59375 \n",
       "L 39.90625 7.59375 \n",
       "Q 39.09375 4.703125 39.09375 0 \n",
       "L 30.59375 0 \n",
       "L 31.09375 4.40625 \n",
       "Q 23.90625 -1 14.90625 -1 \n",
       "Q 10.5 -1 8 0.953125 \n",
       "Q 5.5 2.90625 5.5 6.59375 \n",
       "Q 5.5 23.40625 37.5 29.40625 \n",
       "L 38.296875 32.703125 \n",
       "Q 38.5 33.703125 38.5 34.203125 \n",
       "Q 38.5 36.5 36.546875 37.84375 \n",
       "Q 34.59375 39.203125 31.40625 39.203125 \n",
       "Q 23.796875 39.203125 18.40625 30.203125 \n",
       "z\n",
       "M 33.40625 13.203125 \n",
       "L 35.703125 22.203125 \n",
       "Q 13.90625 18.703125 13.90625 9.59375 \n",
       "Q 13.90625 6.09375 18.703125 6.09375 \n",
       "Q 25.5 6.09375 33.40625 13.203125 \n",
       "\" id=\"STIXGeneral-Italic-1d622\"/>\n",
       "    </defs>\n",
       "    <g transform=\"translate(99.801496063 65.8597883858)scale(0.18 -0.18)\">\n",
       "     <use transform=\"translate(0.0 0.296875)\" xlink:href=\"#STIXGeneral-Regular-2b\"/>\n",
       "     <use transform=\"translate(68.49998474121094 0.296875)\" xlink:href=\"#STIXGeneral-Italic-1d622\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"text_2\">\n",
       "    <!-- $-s$ -->\n",
       "    <defs>\n",
       "     <path d=\"M 62.09375 22 \n",
       "L 6.40625 22 \n",
       "L 6.40625 28.59375 \n",
       "L 62.09375 28.59375 \n",
       "z\n",
       "\" id=\"STIXGeneral-Regular-2212\"/>\n",
       "     <path d=\"M 43.203125 41 \n",
       "L 41 32.09375 \n",
       "L 39.5 32.09375 \n",
       "Q 37.796875 36.5 35.296875 37.890625 \n",
       "Q 32.796875 39.296875 28.890625 39.296875 \n",
       "Q 25 39.296875 23.046875 37.140625 \n",
       "Q 21.09375 35 21.09375 33 \n",
       "Q 21.09375 31 22.796875 29.546875 \n",
       "Q 24.5 28.09375 27.796875 26.5 \n",
       "Q 33.796875 23.59375 36.140625 21.34375 \n",
       "Q 38.5 19.09375 38.5 15.796875 \n",
       "Q 38.5 9 32.890625 4 \n",
       "Q 27.296875 -1 18.59375 -1 \n",
       "Q 14.09375 -1 11.390625 0.296875 \n",
       "Q 8.703125 1.59375 6.09375 4.5 \n",
       "L 8.59375 14.796875 \n",
       "L 10.09375 14.796875 \n",
       "Q 11.90625 6.09375 21 6.09375 \n",
       "Q 24.40625 6.09375 27.296875 7.84375 \n",
       "Q 30.203125 9.59375 30.203125 12.796875 \n",
       "Q 30.203125 14.296875 28.59375 15.640625 \n",
       "Q 27 17 23.203125 18.90625 \n",
       "Q 17.703125 21.59375 15.25 24.25 \n",
       "Q 12.796875 26.90625 12.796875 30.296875 \n",
       "Q 12.796875 36.5 18 41.390625 \n",
       "Q 23.203125 46.296875 30.90625 46.296875 \n",
       "Q 39.59375 46.296875 43.203125 41 \n",
       "\" id=\"STIXGeneral-Italic-1d634\"/>\n",
       "    </defs>\n",
       "    <g transform=\"translate(100.341496063 122.552701772)scale(0.18 -0.18)\">\n",
       "     <use transform=\"translate(0.0 0.703125)\" xlink:href=\"#STIXGeneral-Regular-2212\"/>\n",
       "     <use transform=\"translate(68.49998474121094 0.703125)\" xlink:href=\"#STIXGeneral-Italic-1d634\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"text_3\">\n",
       "    <!-- $-a$ -->\n",
       "    <g transform=\"translate(54.4471653543 65.8597883858)scale(0.18 -0.18)\">\n",
       "     <use transform=\"translate(0.0 0.703125)\" xlink:href=\"#STIXGeneral-Regular-2212\"/>\n",
       "     <use transform=\"translate(68.49998474121094 0.703125)\" xlink:href=\"#STIXGeneral-Italic-1d622\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"text_4\">\n",
       "    <!-- $+s$ -->\n",
       "    <g transform=\"translate(145.695826772 122.552701772)scale(0.18 -0.18)\">\n",
       "     <use transform=\"translate(0.0 0.296875)\" xlink:href=\"#STIXGeneral-Regular-2b\"/>\n",
       "     <use transform=\"translate(68.49998474121094 0.296875)\" xlink:href=\"#STIXGeneral-Italic-1d634\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"text_5\">\n",
       "    <!-- $-l$ -->\n",
       "    <defs>\n",
       "     <path d=\"M 31.296875 67.90625 \n",
       "L 14.40625 0 \n",
       "L 6.09375 0 \n",
       "L 22.5 66 \n",
       "L 30.5 68.40625 \n",
       "z\n",
       "\" id=\"STIXGeneral-Italic-1d62d\"/>\n",
       "    </defs>\n",
       "    <g transform=\"translate(56.6971653543 179.245615157)scale(0.18 -0.18)\">\n",
       "     <use transform=\"translate(0.0 0.59375)\" xlink:href=\"#STIXGeneral-Regular-2212\"/>\n",
       "     <use transform=\"translate(68.49998474121094 0.59375)\" xlink:href=\"#STIXGeneral-Italic-1d62d\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"text_6\">\n",
       "    <!-- $+l$ -->\n",
       "    <g transform=\"translate(102.051496063 179.245615157)scale(0.18 -0.18)\">\n",
       "     <use transform=\"translate(0.0 0.59375)\" xlink:href=\"#STIXGeneral-Regular-2b\"/>\n",
       "     <use transform=\"translate(68.49998474121094 0.59375)\" xlink:href=\"#STIXGeneral-Italic-1d62d\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"text_7\">\n",
       "    <!-- A -->\n",
       "    <defs>\n",
       "     <path d=\"M 34.1875 63.1875 \n",
       "L 20.796875 26.90625 \n",
       "L 47.609375 26.90625 \n",
       "z\n",
       "M 28.609375 72.90625 \n",
       "L 39.796875 72.90625 \n",
       "L 67.578125 0 \n",
       "L 57.328125 0 \n",
       "L 50.6875 18.703125 \n",
       "L 17.828125 18.703125 \n",
       "L 11.1875 0 \n",
       "L 0.78125 0 \n",
       "z\n",
       "\" id=\"BitstreamVeraSans-Roman-41\"/>\n",
       "    </defs>\n",
       "    <g transform=\"translate(81.2277682087 40.5133316929)scale(0.18 -0.18)\">\n",
       "     <use xlink:href=\"#BitstreamVeraSans-Roman-41\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"text_8\">\n",
       "    <!-- L -->\n",
       "    <defs>\n",
       "     <path d=\"M 9.8125 72.90625 \n",
       "L 19.671875 72.90625 \n",
       "L 19.671875 8.296875 \n",
       "L 55.171875 8.296875 \n",
       "L 55.171875 0 \n",
       "L 9.8125 0 \n",
       "z\n",
       "\" id=\"BitstreamVeraSans-Roman-4c\"/>\n",
       "    </defs>\n",
       "    <g transform=\"translate(82.3696432087 153.899158465)scale(0.18 -0.18)\">\n",
       "     <use xlink:href=\"#BitstreamVeraSans-Roman-4c\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"text_9\">\n",
       "    <!-- $(0.8, 0.2)$ -->\n",
       "    <defs>\n",
       "     <path d=\"M 47.703125 33 \n",
       "Q 47.703125 23.796875 45.546875 16.34375 \n",
       "Q 43.40625 8.90625 38.09375 3.75 \n",
       "Q 32.796875 -1.40625 25 -1.40625 \n",
       "Q 18.796875 -1.40625 14.25 1.6875 \n",
       "Q 9.703125 4.796875 7.203125 10.046875 \n",
       "Q 4.703125 15.296875 3.5 21.140625 \n",
       "Q 2.296875 27 2.296875 33.59375 \n",
       "Q 2.296875 42.90625 4.59375 50.34375 \n",
       "Q 6.90625 57.796875 12.296875 62.6875 \n",
       "Q 17.703125 67.59375 25.40625 67.59375 \n",
       "Q 35.203125 67.59375 41.453125 57.9375 \n",
       "Q 47.703125 48.296875 47.703125 33 \n",
       "M 39.796875 33 \n",
       "Q 39.796875 45.203125 35.75 52.84375 \n",
       "Q 31.703125 60.5 25.203125 60.5 \n",
       "Q 17.796875 60.5 14 52.75 \n",
       "Q 10.203125 45 10.203125 33.40625 \n",
       "Q 10.203125 28.203125 10.953125 23.546875 \n",
       "Q 11.703125 18.90625 13.34375 14.75 \n",
       "Q 15 10.59375 18 8.140625 \n",
       "Q 21 5.703125 25 5.703125 \n",
       "Q 30.09375 5.703125 33.546875 9.796875 \n",
       "Q 37 13.90625 38.390625 19.84375 \n",
       "Q 39.796875 25.796875 39.796875 33 \n",
       "\" id=\"STIXGeneral-Regular-1d7e2\"/>\n",
       "     <path d=\"M 46.90625 7.09375 \n",
       "L 44 0 \n",
       "L 3.5 0 \n",
       "L 3.5 2.09375 \n",
       "L 21 23.5 \n",
       "L 21 23.40625 \n",
       "L 26.59375 30.203125 \n",
       "Q 30.5 34.90625 32.09375 36.953125 \n",
       "Q 33.703125 39 35.203125 41.953125 \n",
       "Q 36.703125 44.90625 36.703125 47.5 \n",
       "Q 36.703125 53.703125 33.34375 57.09375 \n",
       "Q 30 60.5 24.203125 60.5 \n",
       "Q 19.59375 60.5 15.75 56.703125 \n",
       "Q 11.90625 52.90625 10.90625 45.90625 \n",
       "L 3.703125 47.59375 \n",
       "Q 5.296875 56.5 11.1875 62.046875 \n",
       "Q 17.09375 67.59375 24.90625 67.59375 \n",
       "Q 33.59375 67.59375 39.09375 62.1875 \n",
       "Q 44.59375 56.796875 44.59375 49.09375 \n",
       "Q 44.59375 43.5 42.5 39.453125 \n",
       "Q 40.40625 35.40625 33.703125 27 \n",
       "L 17.703125 7.09375 \n",
       "z\n",
       "\" id=\"STIXGeneral-Regular-1d7e4\"/>\n",
       "     <path d=\"M 8.296875 -14.09375 \n",
       "L 7.296875 -12.203125 \n",
       "Q 15.59375 -6.59375 15.59375 -1.5 \n",
       "Q 15.59375 -0.203125 14.203125 -0.203125 \n",
       "Q 13.796875 -0.203125 12.84375 -0.390625 \n",
       "Q 11.90625 -0.59375 11.296875 -0.59375 \n",
       "Q 5.5 -0.59375 5.5 4.5 \n",
       "Q 5.5 7.09375 7.140625 8.640625 \n",
       "Q 8.796875 10.203125 11.5 10.203125 \n",
       "Q 14.90625 10.203125 17.203125 7.75 \n",
       "Q 19.5 5.296875 19.5 1.5 \n",
       "Q 19.5 -3.09375 16.453125 -7.390625 \n",
       "Q 13.40625 -11.703125 8.296875 -14.09375 \n",
       "\" id=\"STIXGeneral-Regular-2c\"/>\n",
       "     <path d=\"M 44.703125 16.09375 \n",
       "Q 44.703125 8.796875 39.390625 3.6875 \n",
       "Q 34.09375 -1.40625 24.796875 -1.40625 \n",
       "Q 16.296875 -1.40625 10.59375 3.4375 \n",
       "Q 4.90625 8.296875 4.90625 15.40625 \n",
       "Q 4.90625 20.796875 7.75 25.25 \n",
       "Q 10.59375 29.703125 17.703125 34.5 \n",
       "Q 6 41.40625 6 51.40625 \n",
       "Q 6 58.59375 11.546875 63.09375 \n",
       "Q 17.09375 67.59375 25.59375 67.59375 \n",
       "Q 32.90625 67.59375 37.796875 62.84375 \n",
       "Q 42.703125 58.09375 42.703125 52 \n",
       "Q 42.703125 46.40625 40.09375 42.703125 \n",
       "Q 37.5 39 31.09375 35.296875 \n",
       "Q 44.703125 27 44.703125 16.09375 \n",
       "M 35.5 51.5 \n",
       "Q 35.5 55.5 32.390625 58 \n",
       "Q 29.296875 60.5 24.40625 60.5 \n",
       "Q 19.796875 60.5 16.84375 57.84375 \n",
       "Q 13.90625 55.203125 13.90625 51.796875 \n",
       "Q 13.90625 47.5 16.34375 44.84375 \n",
       "Q 18.796875 42.203125 24.90625 39.40625 \n",
       "Q 35.5 45.203125 35.5 51.5 \n",
       "M 27.59375 28.59375 \n",
       "L 24.09375 30.5 \n",
       "Q 18.90625 28.703125 15.84375 24.640625 \n",
       "Q 12.796875 20.59375 12.796875 16.296875 \n",
       "Q 12.796875 11.796875 16 8.75 \n",
       "Q 19.203125 5.703125 25.203125 5.703125 \n",
       "Q 29.796875 5.703125 33.296875 8.453125 \n",
       "Q 36.796875 11.203125 36.796875 15.796875 \n",
       "Q 36.796875 20 34.6875 22.953125 \n",
       "Q 32.59375 25.90625 27.59375 28.59375 \n",
       "\" id=\"STIXGeneral-Regular-1d7ea\"/>\n",
       "     <path d=\"M 18.09375 4.296875 \n",
       "Q 18.09375 2.09375 16.4375 0.5 \n",
       "Q 14.796875 -1.09375 12.5 -1.09375 \n",
       "Q 10.203125 -1.09375 8.59375 0.5 \n",
       "Q 7 2.09375 7 4.390625 \n",
       "Q 7 6.703125 8.640625 8.34375 \n",
       "Q 10.296875 10 12.59375 10 \n",
       "Q 14.796875 10 16.4375 8.296875 \n",
       "Q 18.09375 6.59375 18.09375 4.296875 \n",
       "\" id=\"STIXGeneral-Regular-2e\"/>\n",
       "     <path d=\"M 30.40625 -16.09375 \n",
       "L 29.203125 -17.703125 \n",
       "Q 17.59375 -11.09375 11.1875 0.5 \n",
       "Q 4.796875 12.09375 4.796875 25.203125 \n",
       "Q 4.796875 52.90625 29.5 67.59375 \n",
       "L 30.40625 66 \n",
       "Q 20.203125 57.296875 16.796875 48.84375 \n",
       "Q 13.40625 40.40625 13.40625 25.5 \n",
       "Q 13.40625 10.703125 16.90625 1.5 \n",
       "Q 20.40625 -7.703125 30.40625 -16.09375 \n",
       "\" id=\"STIXGeneral-Regular-28\"/>\n",
       "     <path d=\"M 2.90625 66 \n",
       "L 4.09375 67.59375 \n",
       "Q 15.5 60.796875 22 49.1875 \n",
       "Q 28.5 37.59375 28.5 24.703125 \n",
       "Q 28.5 -2.59375 3.796875 -17.703125 \n",
       "L 2.90625 -16.09375 \n",
       "Q 13.203125 -7.59375 16.546875 0.84375 \n",
       "Q 19.90625 9.296875 19.90625 24.40625 \n",
       "Q 19.90625 39.59375 16.546875 48.75 \n",
       "Q 13.203125 57.90625 2.90625 66 \n",
       "\" id=\"STIXGeneral-Regular-29\"/>\n",
       "    </defs>\n",
       "    <g transform=\"translate(7.2 97.2062450787)scale(0.18 -0.18)\">\n",
       "     <use transform=\"translate(0.0 0.40625)\" xlink:href=\"#STIXGeneral-Regular-28\"/>\n",
       "     <use transform=\"translate(33.29998779296875 0.40625)\" xlink:href=\"#STIXGeneral-Regular-1d7e2\"/>\n",
       "     <use transform=\"translate(83.29997253417969 0.40625)\" xlink:href=\"#STIXGeneral-Regular-2e\"/>\n",
       "     <use transform=\"translate(123.41995544433594 0.40625)\" xlink:href=\"#STIXGeneral-Regular-1d7ea\"/>\n",
       "     <use transform=\"translate(173.41994018554686 0.40625)\" xlink:href=\"#STIXGeneral-Regular-2c\"/>\n",
       "     <use transform=\"translate(213.5399230957031 0.40625)\" xlink:href=\"#STIXGeneral-Regular-1d7e2\"/>\n",
       "     <use transform=\"translate(263.53990783691404 0.40625)\" xlink:href=\"#STIXGeneral-Regular-2e\"/>\n",
       "     <use transform=\"translate(303.6598907470703 0.40625)\" xlink:href=\"#STIXGeneral-Regular-1d7e4\"/>\n",
       "     <use transform=\"translate(353.6598754882812 0.40625)\" xlink:href=\"#STIXGeneral-Regular-29\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"text_10\">\n",
       "    <!-- S -->\n",
       "    <defs>\n",
       "     <path d=\"M 53.515625 70.515625 \n",
       "L 53.515625 60.890625 \n",
       "Q 47.90625 63.578125 42.921875 64.890625 \n",
       "Q 37.9375 66.21875 33.296875 66.21875 \n",
       "Q 25.25 66.21875 20.875 63.09375 \n",
       "Q 16.5 59.96875 16.5 54.203125 \n",
       "Q 16.5 49.359375 19.40625 46.890625 \n",
       "Q 22.3125 44.4375 30.421875 42.921875 \n",
       "L 36.375 41.703125 \n",
       "Q 47.40625 39.59375 52.65625 34.296875 \n",
       "Q 57.90625 29 57.90625 20.125 \n",
       "Q 57.90625 9.515625 50.796875 4.046875 \n",
       "Q 43.703125 -1.421875 29.984375 -1.421875 \n",
       "Q 24.8125 -1.421875 18.96875 -0.25 \n",
       "Q 13.140625 0.921875 6.890625 3.21875 \n",
       "L 6.890625 13.375 \n",
       "Q 12.890625 10.015625 18.65625 8.296875 \n",
       "Q 24.421875 6.59375 29.984375 6.59375 \n",
       "Q 38.421875 6.59375 43.015625 9.90625 \n",
       "Q 47.609375 13.234375 47.609375 19.390625 \n",
       "Q 47.609375 24.75 44.3125 27.78125 \n",
       "Q 41.015625 30.8125 33.5 32.328125 \n",
       "L 27.484375 33.5 \n",
       "Q 16.453125 35.6875 11.515625 40.375 \n",
       "Q 6.59375 45.0625 6.59375 53.421875 \n",
       "Q 6.59375 63.09375 13.40625 68.65625 \n",
       "Q 20.21875 74.21875 32.171875 74.21875 \n",
       "Q 37.3125 74.21875 42.625 73.28125 \n",
       "Q 47.953125 72.359375 53.515625 70.515625 \n",
       "\" id=\"BitstreamVeraSans-Roman-53\"/>\n",
       "    </defs>\n",
       "    <g transform=\"translate(127.025067667 97.2062450787)scale(0.18 -0.18)\">\n",
       "     <use xlink:href=\"#BitstreamVeraSans-Roman-53\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"text_11\">\n",
       "    <!-- $(0.9, 0.1)$ -->\n",
       "    <defs>\n",
       "     <path d=\"M 5.5 -0.203125 \n",
       "L 6.796875 4.703125 \n",
       "Q 18.203125 5.5 26.140625 11.25 \n",
       "Q 34.09375 17 37.59375 27.5 \n",
       "Q 31.796875 23.09375 23.90625 23.09375 \n",
       "Q 15.296875 23.09375 9.046875 28.890625 \n",
       "Q 2.796875 34.703125 2.796875 44.203125 \n",
       "Q 2.796875 53.90625 8.84375 60.75 \n",
       "Q 14.90625 67.59375 24.203125 67.59375 \n",
       "Q 30.09375 67.59375 34.5 65.34375 \n",
       "Q 38.90625 63.09375 41.5 59.09375 \n",
       "Q 44.09375 55.09375 45.34375 50.25 \n",
       "Q 46.59375 45.40625 46.59375 39.796875 \n",
       "Q 46.59375 31.40625 43.546875 23.203125 \n",
       "Q 40.5 15 35.5 10.09375 \n",
       "Q 28.796875 3.59375 22.84375 1.296875 \n",
       "Q 16.90625 -1 5.703125 -2.09375 \n",
       "z\n",
       "M 38.59375 42.203125 \n",
       "Q 38.5 50.296875 34.546875 55.390625 \n",
       "Q 30.59375 60.5 23.90625 60.5 \n",
       "Q 18.40625 60.5 14.59375 56.296875 \n",
       "Q 10.796875 52.09375 10.796875 45.59375 \n",
       "Q 10.796875 38.40625 14.890625 34.34375 \n",
       "Q 19 30.296875 24.703125 30.296875 \n",
       "Q 29.90625 30.296875 33.796875 33.34375 \n",
       "Q 37.703125 36.40625 38.59375 42.203125 \n",
       "\" id=\"STIXGeneral-Regular-1d7eb\"/>\n",
       "     <path d=\"M 30.203125 0 \n",
       "L 22.296875 0 \n",
       "L 22.296875 57 \n",
       "Q 20.09375 56 15.75 53.75 \n",
       "Q 11.40625 51.5 10.796875 51.203125 \n",
       "L 10.796875 58.5 \n",
       "L 28.796875 67.703125 \n",
       "L 30.203125 67.203125 \n",
       "z\n",
       "\" id=\"STIXGeneral-Regular-1d7e3\"/>\n",
       "    </defs>\n",
       "    <g transform=\"translate(7.2 210.59207185)scale(0.18 -0.18)\">\n",
       "     <use transform=\"translate(0.0 0.296875)\" xlink:href=\"#STIXGeneral-Regular-28\"/>\n",
       "     <use transform=\"translate(33.29998779296875 0.296875)\" xlink:href=\"#STIXGeneral-Regular-1d7e2\"/>\n",
       "     <use transform=\"translate(83.29997253417969 0.296875)\" xlink:href=\"#STIXGeneral-Regular-2e\"/>\n",
       "     <use transform=\"translate(123.41995544433594 0.296875)\" xlink:href=\"#STIXGeneral-Regular-1d7eb\"/>\n",
       "     <use transform=\"translate(173.41994018554686 0.296875)\" xlink:href=\"#STIXGeneral-Regular-2c\"/>\n",
       "     <use transform=\"translate(213.5399230957031 0.296875)\" xlink:href=\"#STIXGeneral-Regular-1d7e2\"/>\n",
       "     <use transform=\"translate(263.53990783691404 0.296875)\" xlink:href=\"#STIXGeneral-Regular-2e\"/>\n",
       "     <use transform=\"translate(303.6598907470703 0.296875)\" xlink:href=\"#STIXGeneral-Regular-1d7e3\"/>\n",
       "     <use transform=\"translate(353.6598754882812 0.296875)\" xlink:href=\"#STIXGeneral-Regular-29\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"text_12\">\n",
       "    <!-- $(0.1, 0.9)$ -->\n",
       "    <g transform=\"translate(143.262992126 153.899158465)scale(0.18 -0.18)\">\n",
       "     <use transform=\"translate(0.0 0.296875)\" xlink:href=\"#STIXGeneral-Regular-28\"/>\n",
       "     <use transform=\"translate(33.29998779296875 0.296875)\" xlink:href=\"#STIXGeneral-Regular-1d7e2\"/>\n",
       "     <use transform=\"translate(83.29997253417969 0.296875)\" xlink:href=\"#STIXGeneral-Regular-2e\"/>\n",
       "     <use transform=\"translate(123.41995544433594 0.296875)\" xlink:href=\"#STIXGeneral-Regular-1d7e3\"/>\n",
       "     <use transform=\"translate(173.41994018554686 0.296875)\" xlink:href=\"#STIXGeneral-Regular-2c\"/>\n",
       "     <use transform=\"translate(213.5399230957031 0.296875)\" xlink:href=\"#STIXGeneral-Regular-1d7e2\"/>\n",
       "     <use transform=\"translate(263.53990783691404 0.296875)\" xlink:href=\"#STIXGeneral-Regular-2e\"/>\n",
       "     <use transform=\"translate(303.6598907470703 0.296875)\" xlink:href=\"#STIXGeneral-Regular-1d7eb\"/>\n",
       "     <use transform=\"translate(353.6598754882812 0.296875)\" xlink:href=\"#STIXGeneral-Regular-29\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"text_13\">\n",
       "    <!-- $(0.4, 0.6)$ -->\n",
       "    <defs>\n",
       "     <path d=\"M 48.90625 23.59375 \n",
       "L 45.59375 16.5 \n",
       "L 37.296875 16.5 \n",
       "L 37.296875 0 \n",
       "L 29.40625 0 \n",
       "L 29.40625 16.5 \n",
       "L 1.09375 16.5 \n",
       "L 1.09375 23.296875 \n",
       "L 32.296875 67.59375 \n",
       "L 37.296875 67.59375 \n",
       "L 37.296875 23.59375 \n",
       "z\n",
       "M 29.40625 23.59375 \n",
       "L 29.40625 51 \n",
       "L 10 23.59375 \n",
       "z\n",
       "\" id=\"STIXGeneral-Regular-1d7e6\"/>\n",
       "     <path d=\"M 44.796875 66.796875 \n",
       "L 43 61.5 \n",
       "Q 31.59375 60.703125 23.640625 54.953125 \n",
       "Q 15.703125 49.203125 12.203125 38.796875 \n",
       "Q 18.09375 43.09375 25.90625 43.09375 \n",
       "Q 34.5 43.09375 40.75 37.296875 \n",
       "Q 47 31.5 47 22 \n",
       "Q 47 12.296875 40.953125 5.4375 \n",
       "Q 34.90625 -1.40625 25.703125 -1.40625 \n",
       "Q 18 -1.40625 12.75 2.640625 \n",
       "Q 7.5 6.703125 5.34375 12.75 \n",
       "Q 3.203125 18.796875 3.203125 26.40625 \n",
       "Q 3.203125 34.90625 6.203125 43.046875 \n",
       "Q 9.203125 51.203125 14.296875 56.203125 \n",
       "Q 21 62.796875 27.09375 65.046875 \n",
       "Q 33.203125 67.296875 44.703125 68.40625 \n",
       "z\n",
       "M 39 20.703125 \n",
       "Q 39 27.90625 34.890625 31.953125 \n",
       "Q 30.796875 36 25.09375 36 \n",
       "Q 19.90625 36 16 32.953125 \n",
       "Q 12.09375 29.90625 11.203125 24 \n",
       "Q 11.203125 15.90625 15.203125 10.796875 \n",
       "Q 19.203125 5.703125 26 5.703125 \n",
       "Q 31.5 5.703125 35.25 9.953125 \n",
       "Q 39 14.203125 39 20.703125 \n",
       "\" id=\"STIXGeneral-Regular-1d7e8\"/>\n",
       "    </defs>\n",
       "    <g transform=\"translate(97.9086614173 210.59207185)scale(0.18 -0.18)\">\n",
       "     <use transform=\"translate(0.0 0.59375)\" xlink:href=\"#STIXGeneral-Regular-28\"/>\n",
       "     <use transform=\"translate(33.29998779296875 0.59375)\" xlink:href=\"#STIXGeneral-Regular-1d7e2\"/>\n",
       "     <use transform=\"translate(83.29997253417969 0.59375)\" xlink:href=\"#STIXGeneral-Regular-2e\"/>\n",
       "     <use transform=\"translate(123.41995544433594 0.59375)\" xlink:href=\"#STIXGeneral-Regular-1d7e6\"/>\n",
       "     <use transform=\"translate(173.41994018554686 0.59375)\" xlink:href=\"#STIXGeneral-Regular-2c\"/>\n",
       "     <use transform=\"translate(213.5399230957031 0.59375)\" xlink:href=\"#STIXGeneral-Regular-1d7e2\"/>\n",
       "     <use transform=\"translate(263.53990783691404 0.59375)\" xlink:href=\"#STIXGeneral-Regular-2e\"/>\n",
       "     <use transform=\"translate(303.6598907470703 0.59375)\" xlink:href=\"#STIXGeneral-Regular-1d7e8\"/>\n",
       "     <use transform=\"translate(353.6598754882812 0.59375)\" xlink:href=\"#STIXGeneral-Regular-29\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "  </g>\n",
       " </g>\n",
       " <defs>\n",
       "  <clipPath id=\"p93cbb209c9\">\n",
       "   <rect height=\"226.771653543\" width=\"226.771653543\" x=\"13.6835433071\" y=\"7.2\"/>\n",
       "  </clipPath>\n",
       " </defs>\n",
       "</svg>\n"
      ],
      "text/plain": [
       "<matplotlib.figure.Figure at 0x7feb96e669e8>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "pgm = daft.PGM([4, 4], origin=[-0.5, 0.5])\n",
    "add_node(pgm, 'a', 'A', 0.8, 4)\n",
    "add_node(pgm, 't1', '$(0.8, 0.2)$', 0, 3, plot_params={'edgecolor': 'none'})\n",
    "add_node(pgm, 'l', 'L', 0.8, 2)\n",
    "add_node(pgm, 's', 'S', 1.6, 3)\n",
    "add_node(pgm, 't2', '$(0.1, 0.9)$', 2.4, 2, plot_params={'edgecolor': 'none'})\n",
    "add_node(pgm, 't3', '$(0.9, 0.1)$', 0, 1, plot_params={'edgecolor': 'none'})\n",
    "add_node(pgm, 't4', '$(0.4, 0.6)$', 1.6, 1, plot_params={'edgecolor': 'none'})\n",
    "add_edges(pgm, [\n",
    "        ('a', 's', '$+a$'),\n",
    "        ('s', 'l', '$-s$'),\n",
    "        ('a', 't1', '$-a$'),\n",
    "        ('s', 't2', '$+s$'),\n",
    "        ('l', 't3', '$-l$'),\n",
    "        ('l', 't4', '$+l$')\n",
    "    ])\n",
    "pgm.render()\n",
    "save('bn_tree_cpd_01')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "image/svg+xml": [
       "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"no\"?>\n",
       "<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\n",
       "  \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n",
       "<!-- Created with matplotlib (http://matplotlib.org/) -->\n",
       "<svg height=\"127pt\" version=\"1.1\" viewBox=\"0 0 156 127\" width=\"156pt\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n",
       " <defs>\n",
       "  <style type=\"text/css\">\n",
       "*{stroke-linecap:butt;stroke-linejoin:round;stroke-miterlimit:100000;}\n",
       "  </style>\n",
       " </defs>\n",
       " <g id=\"figure_1\">\n",
       "  <g id=\"patch_1\">\n",
       "   <path d=\"M 0 127.785827 \n",
       "L 156.132283 127.785827 \n",
       "L 156.132283 0 \n",
       "L 0 0 \n",
       "L 0 127.785827 \n",
       "z\n",
       "\" style=\"fill:none;\"/>\n",
       "  </g>\n",
       "  <g id=\"axes_1\">\n",
       "   <g id=\"patch_2\">\n",
       "    <path clip-path=\"url(#pe68eff206f)\" d=\"M 92.92717 68.874404 \n",
       "L 93.42827 65.366709 \n",
       "L 94.931568 66.870007 \n",
       "L 114.228735 47.57284 \n",
       "L 114.228735 47.57284 \n",
       "L 94.931568 66.870007 \n",
       "L 96.434866 68.373305 \n",
       "L 92.92717 68.874404 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_3\">\n",
       "    <path clip-path=\"url(#pe68eff206f)\" d=\"M 80.900787 63.892913 \n",
       "L 78.774803 61.058268 \n",
       "L 80.900787 61.058268 \n",
       "L 80.900787 52.554331 \n",
       "L 80.900787 52.554331 \n",
       "L 80.900787 61.058268 \n",
       "L 83.026772 61.058268 \n",
       "L 80.900787 63.892913 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_4\">\n",
       "    <path clip-path=\"url(#pe68eff206f)\" d=\"M 68.874404 68.874404 \n",
       "L 65.366709 68.373305 \n",
       "L 66.870007 66.870007 \n",
       "L 47.57284 47.57284 \n",
       "L 47.57284 47.57284 \n",
       "L 66.870007 66.870007 \n",
       "L 68.373305 65.366709 \n",
       "L 68.874404 68.874404 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_5\">\n",
       "    <path clip-path=\"url(#pe68eff206f)\" d=\"M 35.546457 52.554331 \n",
       "C 40.056998 52.554331 44.383406 50.762274 47.57284 47.57284 \n",
       "C 50.762274 44.383406 52.554331 40.056998 52.554331 35.546457 \n",
       "C 52.554331 31.035916 50.762274 26.709508 47.57284 23.520074 \n",
       "C 44.383406 20.33064 40.056998 18.538583 35.546457 18.538583 \n",
       "C 31.035916 18.538583 26.709508 20.33064 23.520074 23.520074 \n",
       "C 20.33064 26.709508 18.538583 31.035916 18.538583 35.546457 \n",
       "C 18.538583 40.056998 20.33064 44.383406 23.520074 47.57284 \n",
       "C 26.709508 50.762274 31.035916 52.554331 35.546457 52.554331 \n",
       "L 35.546457 52.554331 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_6\">\n",
       "    <path clip-path=\"url(#pe68eff206f)\" d=\"M 80.900787 52.554331 \n",
       "C 85.411328 52.554331 89.737736 50.762274 92.92717 47.57284 \n",
       "C 96.116605 44.383406 97.908661 40.056998 97.908661 35.546457 \n",
       "C 97.908661 31.035916 96.116605 26.709508 92.92717 23.520074 \n",
       "C 89.737736 20.33064 85.411328 18.538583 80.900787 18.538583 \n",
       "C 76.390246 18.538583 72.063838 20.33064 68.874404 23.520074 \n",
       "C 65.68497 26.709508 63.892913 31.035916 63.892913 35.546457 \n",
       "C 63.892913 40.056998 65.68497 44.383406 68.874404 47.57284 \n",
       "C 72.063838 50.762274 76.390246 52.554331 80.900787 52.554331 \n",
       "L 80.900787 52.554331 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_7\">\n",
       "    <path clip-path=\"url(#pe68eff206f)\" d=\"M 80.900787 97.908661 \n",
       "C 85.411328 97.908661 89.737736 96.116605 92.92717 92.92717 \n",
       "C 96.116605 89.737736 97.908661 85.411328 97.908661 80.900787 \n",
       "C 97.908661 76.390246 96.116605 72.063838 92.92717 68.874404 \n",
       "C 89.737736 65.68497 85.411328 63.892913 80.900787 63.892913 \n",
       "C 76.390246 63.892913 72.063838 65.68497 68.874404 68.874404 \n",
       "C 65.68497 72.063838 63.892913 76.390246 63.892913 80.900787 \n",
       "C 63.892913 85.411328 65.68497 89.737736 68.874404 92.92717 \n",
       "C 72.063838 96.116605 76.390246 97.908661 80.900787 97.908661 \n",
       "L 80.900787 97.908661 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_8\">\n",
       "    <path clip-path=\"url(#pe68eff206f)\" d=\"M 126.255118 52.554331 \n",
       "C 130.765659 52.554331 135.092067 50.762274 138.281501 47.57284 \n",
       "C 141.470935 44.383406 143.262992 40.056998 143.262992 35.546457 \n",
       "C 143.262992 31.035916 141.470935 26.709508 138.281501 23.520074 \n",
       "C 135.092067 20.33064 130.765659 18.538583 126.255118 18.538583 \n",
       "C 121.744577 18.538583 117.418169 20.33064 114.228735 23.520074 \n",
       "C 111.039301 26.709508 109.247244 31.035916 109.247244 35.546457 \n",
       "C 109.247244 40.056998 111.039301 44.383406 114.228735 47.57284 \n",
       "C 117.418169 50.762274 121.744577 52.554331 126.255118 52.554331 \n",
       "L 126.255118 52.554331 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"matplotlib.axis_1\"/>\n",
       "   <g id=\"matplotlib.axis_2\"/>\n",
       "   <g id=\"text_1\">\n",
       "    <!-- letter 1 -->\n",
       "    <defs>\n",
       "     <path d=\"M 18.3125 70.21875 \n",
       "L 18.3125 54.6875 \n",
       "L 36.8125 54.6875 \n",
       "L 36.8125 47.703125 \n",
       "L 18.3125 47.703125 \n",
       "L 18.3125 18.015625 \n",
       "Q 18.3125 11.328125 20.140625 9.421875 \n",
       "Q 21.96875 7.515625 27.59375 7.515625 \n",
       "L 36.8125 7.515625 \n",
       "L 36.8125 0 \n",
       "L 27.59375 0 \n",
       "Q 17.1875 0 13.234375 3.875 \n",
       "Q 9.28125 7.765625 9.28125 18.015625 \n",
       "L 9.28125 47.703125 \n",
       "L 2.6875 47.703125 \n",
       "L 2.6875 54.6875 \n",
       "L 9.28125 54.6875 \n",
       "L 9.28125 70.21875 \n",
       "z\n",
       "\" id=\"BitstreamVeraSans-Roman-74\"/>\n",
       "     <path d=\"M 41.109375 46.296875 \n",
       "Q 39.59375 47.171875 37.8125 47.578125 \n",
       "Q 36.03125 48 33.890625 48 \n",
       "Q 26.265625 48 22.1875 43.046875 \n",
       "Q 18.109375 38.09375 18.109375 28.8125 \n",
       "L 18.109375 0 \n",
       "L 9.078125 0 \n",
       "L 9.078125 54.6875 \n",
       "L 18.109375 54.6875 \n",
       "L 18.109375 46.1875 \n",
       "Q 20.953125 51.171875 25.484375 53.578125 \n",
       "Q 30.03125 56 36.53125 56 \n",
       "Q 37.453125 56 38.578125 55.875 \n",
       "Q 39.703125 55.765625 41.0625 55.515625 \n",
       "z\n",
       "\" id=\"BitstreamVeraSans-Roman-72\"/>\n",
       "     <path id=\"BitstreamVeraSans-Roman-20\"/>\n",
       "     <path d=\"M 9.421875 75.984375 \n",
       "L 18.40625 75.984375 \n",
       "L 18.40625 0 \n",
       "L 9.421875 0 \n",
       "z\n",
       "\" id=\"BitstreamVeraSans-Roman-6c\"/>\n",
       "     <path d=\"M 56.203125 29.59375 \n",
       "L 56.203125 25.203125 \n",
       "L 14.890625 25.203125 \n",
       "Q 15.484375 15.921875 20.484375 11.0625 \n",
       "Q 25.484375 6.203125 34.421875 6.203125 \n",
       "Q 39.59375 6.203125 44.453125 7.46875 \n",
       "Q 49.3125 8.734375 54.109375 11.28125 \n",
       "L 54.109375 2.78125 \n",
       "Q 49.265625 0.734375 44.1875 -0.34375 \n",
       "Q 39.109375 -1.421875 33.890625 -1.421875 \n",
       "Q 20.796875 -1.421875 13.15625 6.1875 \n",
       "Q 5.515625 13.8125 5.515625 26.8125 \n",
       "Q 5.515625 40.234375 12.765625 48.109375 \n",
       "Q 20.015625 56 32.328125 56 \n",
       "Q 43.359375 56 49.78125 48.890625 \n",
       "Q 56.203125 41.796875 56.203125 29.59375 \n",
       "M 47.21875 32.234375 \n",
       "Q 47.125 39.59375 43.09375 43.984375 \n",
       "Q 39.0625 48.390625 32.421875 48.390625 \n",
       "Q 24.90625 48.390625 20.390625 44.140625 \n",
       "Q 15.875 39.890625 15.1875 32.171875 \n",
       "z\n",
       "\" id=\"BitstreamVeraSans-Roman-65\"/>\n",
       "     <path d=\"M 12.40625 8.296875 \n",
       "L 28.515625 8.296875 \n",
       "L 28.515625 63.921875 \n",
       "L 10.984375 60.40625 \n",
       "L 10.984375 69.390625 \n",
       "L 28.421875 72.90625 \n",
       "L 38.28125 72.90625 \n",
       "L 38.28125 8.296875 \n",
       "L 54.390625 8.296875 \n",
       "L 54.390625 0 \n",
       "L 12.40625 0 \n",
       "z\n",
       "\" id=\"BitstreamVeraSans-Roman-31\"/>\n",
       "    </defs>\n",
       "    <g transform=\"translate(20.9158316929 37.7539566929)scale(0.08 -0.08)\">\n",
       "     <use xlink:href=\"#BitstreamVeraSans-Roman-6c\"/>\n",
       "     <use x=\"27.783203125\" xlink:href=\"#BitstreamVeraSans-Roman-65\"/>\n",
       "     <use x=\"89.306640625\" xlink:href=\"#BitstreamVeraSans-Roman-74\"/>\n",
       "     <use x=\"128.515625\" xlink:href=\"#BitstreamVeraSans-Roman-74\"/>\n",
       "     <use x=\"167.724609375\" xlink:href=\"#BitstreamVeraSans-Roman-65\"/>\n",
       "     <use x=\"229.248046875\" xlink:href=\"#BitstreamVeraSans-Roman-72\"/>\n",
       "     <use x=\"270.361328125\" xlink:href=\"#BitstreamVeraSans-Roman-20\"/>\n",
       "     <use x=\"302.1484375\" xlink:href=\"#BitstreamVeraSans-Roman-31\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"text_2\">\n",
       "    <!-- choice -->\n",
       "    <defs>\n",
       "     <path d=\"M 48.78125 52.59375 \n",
       "L 48.78125 44.1875 \n",
       "Q 44.96875 46.296875 41.140625 47.34375 \n",
       "Q 37.3125 48.390625 33.40625 48.390625 \n",
       "Q 24.65625 48.390625 19.8125 42.84375 \n",
       "Q 14.984375 37.3125 14.984375 27.296875 \n",
       "Q 14.984375 17.28125 19.8125 11.734375 \n",
       "Q 24.65625 6.203125 33.40625 6.203125 \n",
       "Q 37.3125 6.203125 41.140625 7.25 \n",
       "Q 44.96875 8.296875 48.78125 10.40625 \n",
       "L 48.78125 2.09375 \n",
       "Q 45.015625 0.34375 40.984375 -0.53125 \n",
       "Q 36.96875 -1.421875 32.421875 -1.421875 \n",
       "Q 20.0625 -1.421875 12.78125 6.34375 \n",
       "Q 5.515625 14.109375 5.515625 27.296875 \n",
       "Q 5.515625 40.671875 12.859375 48.328125 \n",
       "Q 20.21875 56 33.015625 56 \n",
       "Q 37.15625 56 41.109375 55.140625 \n",
       "Q 45.0625 54.296875 48.78125 52.59375 \n",
       "\" id=\"BitstreamVeraSans-Roman-63\"/>\n",
       "     <path d=\"M 9.421875 54.6875 \n",
       "L 18.40625 54.6875 \n",
       "L 18.40625 0 \n",
       "L 9.421875 0 \n",
       "z\n",
       "M 9.421875 75.984375 \n",
       "L 18.40625 75.984375 \n",
       "L 18.40625 64.59375 \n",
       "L 9.421875 64.59375 \n",
       "z\n",
       "\" id=\"BitstreamVeraSans-Roman-69\"/>\n",
       "     <path d=\"M 54.890625 33.015625 \n",
       "L 54.890625 0 \n",
       "L 45.90625 0 \n",
       "L 45.90625 32.71875 \n",
       "Q 45.90625 40.484375 42.875 44.328125 \n",
       "Q 39.84375 48.1875 33.796875 48.1875 \n",
       "Q 26.515625 48.1875 22.3125 43.546875 \n",
       "Q 18.109375 38.921875 18.109375 30.90625 \n",
       "L 18.109375 0 \n",
       "L 9.078125 0 \n",
       "L 9.078125 75.984375 \n",
       "L 18.109375 75.984375 \n",
       "L 18.109375 46.1875 \n",
       "Q 21.34375 51.125 25.703125 53.5625 \n",
       "Q 30.078125 56 35.796875 56 \n",
       "Q 45.21875 56 50.046875 50.171875 \n",
       "Q 54.890625 44.34375 54.890625 33.015625 \n",
       "\" id=\"BitstreamVeraSans-Roman-68\"/>\n",
       "     <path d=\"M 30.609375 48.390625 \n",
       "Q 23.390625 48.390625 19.1875 42.75 \n",
       "Q 14.984375 37.109375 14.984375 27.296875 \n",
       "Q 14.984375 17.484375 19.15625 11.84375 \n",
       "Q 23.34375 6.203125 30.609375 6.203125 \n",
       "Q 37.796875 6.203125 41.984375 11.859375 \n",
       "Q 46.1875 17.53125 46.1875 27.296875 \n",
       "Q 46.1875 37.015625 41.984375 42.703125 \n",
       "Q 37.796875 48.390625 30.609375 48.390625 \n",
       "M 30.609375 56 \n",
       "Q 42.328125 56 49.015625 48.375 \n",
       "Q 55.71875 40.765625 55.71875 27.296875 \n",
       "Q 55.71875 13.875 49.015625 6.21875 \n",
       "Q 42.328125 -1.421875 30.609375 -1.421875 \n",
       "Q 18.84375 -1.421875 12.171875 6.21875 \n",
       "Q 5.515625 13.875 5.515625 27.296875 \n",
       "Q 5.515625 40.765625 12.171875 48.375 \n",
       "Q 18.84375 56 30.609375 56 \n",
       "\" id=\"BitstreamVeraSans-Roman-6f\"/>\n",
       "    </defs>\n",
       "    <g transform=\"translate(66.3278186516 38.0298941929)scale(0.09 -0.09)\">\n",
       "     <use xlink:href=\"#BitstreamVeraSans-Roman-63\"/>\n",
       "     <use x=\"54.98046875\" xlink:href=\"#BitstreamVeraSans-Roman-68\"/>\n",
       "     <use x=\"118.359375\" xlink:href=\"#BitstreamVeraSans-Roman-6f\"/>\n",
       "     <use x=\"179.541015625\" xlink:href=\"#BitstreamVeraSans-Roman-69\"/>\n",
       "     <use x=\"207.32421875\" xlink:href=\"#BitstreamVeraSans-Roman-63\"/>\n",
       "     <use x=\"262.3046875\" xlink:href=\"#BitstreamVeraSans-Roman-65\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"text_3\">\n",
       "    <!-- job -->\n",
       "    <defs>\n",
       "     <path d=\"M 9.421875 54.6875 \n",
       "L 18.40625 54.6875 \n",
       "L 18.40625 -0.984375 \n",
       "Q 18.40625 -11.421875 14.421875 -16.109375 \n",
       "Q 10.453125 -20.796875 1.609375 -20.796875 \n",
       "L -1.8125 -20.796875 \n",
       "L -1.8125 -13.1875 \n",
       "L 0.59375 -13.1875 \n",
       "Q 5.71875 -13.1875 7.5625 -10.8125 \n",
       "Q 9.421875 -8.453125 9.421875 -0.984375 \n",
       "z\n",
       "M 9.421875 75.984375 \n",
       "L 18.40625 75.984375 \n",
       "L 18.40625 64.59375 \n",
       "L 9.421875 64.59375 \n",
       "z\n",
       "\" id=\"BitstreamVeraSans-Roman-6a\"/>\n",
       "     <path d=\"M 48.6875 27.296875 \n",
       "Q 48.6875 37.203125 44.609375 42.84375 \n",
       "Q 40.53125 48.484375 33.40625 48.484375 \n",
       "Q 26.265625 48.484375 22.1875 42.84375 \n",
       "Q 18.109375 37.203125 18.109375 27.296875 \n",
       "Q 18.109375 17.390625 22.1875 11.75 \n",
       "Q 26.265625 6.109375 33.40625 6.109375 \n",
       "Q 40.53125 6.109375 44.609375 11.75 \n",
       "Q 48.6875 17.390625 48.6875 27.296875 \n",
       "M 18.109375 46.390625 \n",
       "Q 20.953125 51.265625 25.265625 53.625 \n",
       "Q 29.59375 56 35.59375 56 \n",
       "Q 45.5625 56 51.78125 48.09375 \n",
       "Q 58.015625 40.1875 58.015625 27.296875 \n",
       "Q 58.015625 14.40625 51.78125 6.484375 \n",
       "Q 45.5625 -1.421875 35.59375 -1.421875 \n",
       "Q 29.59375 -1.421875 25.265625 0.953125 \n",
       "Q 20.953125 3.328125 18.109375 8.203125 \n",
       "L 18.109375 0 \n",
       "L 9.078125 0 \n",
       "L 9.078125 75.984375 \n",
       "L 18.109375 75.984375 \n",
       "z\n",
       "\" id=\"BitstreamVeraSans-Roman-62\"/>\n",
       "    </defs>\n",
       "    <g transform=\"translate(72.5158655266 83.9360999016)scale(0.11 -0.11)\">\n",
       "     <use xlink:href=\"#BitstreamVeraSans-Roman-6a\"/>\n",
       "     <use x=\"27.783203125\" xlink:href=\"#BitstreamVeraSans-Roman-6f\"/>\n",
       "     <use x=\"88.96484375\" xlink:href=\"#BitstreamVeraSans-Roman-62\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"text_4\">\n",
       "    <!-- letter 2 -->\n",
       "    <defs>\n",
       "     <path d=\"M 19.1875 8.296875 \n",
       "L 53.609375 8.296875 \n",
       "L 53.609375 0 \n",
       "L 7.328125 0 \n",
       "L 7.328125 8.296875 \n",
       "Q 12.9375 14.109375 22.625 23.890625 \n",
       "Q 32.328125 33.6875 34.8125 36.53125 \n",
       "Q 39.546875 41.84375 41.421875 45.53125 \n",
       "Q 43.3125 49.21875 43.3125 52.78125 \n",
       "Q 43.3125 58.59375 39.234375 62.25 \n",
       "Q 35.15625 65.921875 28.609375 65.921875 \n",
       "Q 23.96875 65.921875 18.8125 64.3125 \n",
       "Q 13.671875 62.703125 7.8125 59.421875 \n",
       "L 7.8125 69.390625 \n",
       "Q 13.765625 71.78125 18.9375 73 \n",
       "Q 24.125 74.21875 28.421875 74.21875 \n",
       "Q 39.75 74.21875 46.484375 68.546875 \n",
       "Q 53.21875 62.890625 53.21875 53.421875 \n",
       "Q 53.21875 48.921875 51.53125 44.890625 \n",
       "Q 49.859375 40.875 45.40625 35.40625 \n",
       "Q 44.1875 33.984375 37.640625 27.21875 \n",
       "Q 31.109375 20.453125 19.1875 8.296875 \n",
       "\" id=\"BitstreamVeraSans-Roman-32\"/>\n",
       "    </defs>\n",
       "    <g transform=\"translate(111.62449311 37.7539566929)scale(0.08 -0.08)\">\n",
       "     <use xlink:href=\"#BitstreamVeraSans-Roman-6c\"/>\n",
       "     <use x=\"27.783203125\" xlink:href=\"#BitstreamVeraSans-Roman-65\"/>\n",
       "     <use x=\"89.306640625\" xlink:href=\"#BitstreamVeraSans-Roman-74\"/>\n",
       "     <use x=\"128.515625\" xlink:href=\"#BitstreamVeraSans-Roman-74\"/>\n",
       "     <use x=\"167.724609375\" xlink:href=\"#BitstreamVeraSans-Roman-65\"/>\n",
       "     <use x=\"229.248046875\" xlink:href=\"#BitstreamVeraSans-Roman-72\"/>\n",
       "     <use x=\"270.361328125\" xlink:href=\"#BitstreamVeraSans-Roman-20\"/>\n",
       "     <use x=\"302.1484375\" xlink:href=\"#BitstreamVeraSans-Roman-32\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "  </g>\n",
       " </g>\n",
       " <defs>\n",
       "  <clipPath id=\"pe68eff206f\">\n",
       "   <rect height=\"113.385826772\" width=\"141.732283465\" x=\"7.2\" y=\"7.2\"/>\n",
       "  </clipPath>\n",
       " </defs>\n",
       "</svg>\n"
      ],
      "text/plain": [
       "<matplotlib.figure.Figure at 0x7feb96e662b0>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "pgm = daft.PGM([2.5, 2], origin=[-0.5, 0.5])\n",
    "add_node(pgm, 'l1', 'letter 1', 0, 2, label_params={'size':8})\n",
    "add_node(pgm, 'j', 'job', 0.8, 1.2, label_params={'size':11})\n",
    "add_node(pgm, 'c', 'choice', 0.8, 2, label_params={'size':9})\n",
    "add_node(pgm, 'l2', 'letter 2', 1.6, 2, label_params={'size':8})\n",
    "add_edges(pgm, [\n",
    "        ('l2', 'j'),\n",
    "        ('c', 'j'),\n",
    "        ('l1', 'j')\n",
    "    ])\n",
    "pgm.render()\n",
    "save('bn_tree_cpd_02')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "metadata": {
    "collapsed": false,
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "image/svg+xml": [
       "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"no\"?>\n",
       "<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\n",
       "  \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n",
       "<!-- Created with matplotlib (http://matplotlib.org/) -->\n",
       "<svg height=\"184pt\" version=\"1.1\" viewBox=\"0 0 361 184\" width=\"361pt\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n",
       " <defs>\n",
       "  <style type=\"text/css\">\n",
       "*{stroke-linecap:butt;stroke-linejoin:round;stroke-miterlimit:100000;}\n",
       "  </style>\n",
       " </defs>\n",
       " <g id=\"figure_1\">\n",
       "  <g id=\"patch_1\">\n",
       "   <path d=\"M 0 184.47874 \n",
       "L 361.041024 184.47874 \n",
       "L 361.041024 0 \n",
       "L 0 0 \n",
       "L 0 184.47874 \n",
       "z\n",
       "\" style=\"fill:none;\"/>\n",
       "  </g>\n",
       "  <g id=\"axes_1\">\n",
       "   <g id=\"patch_2\">\n",
       "    <path clip-path=\"url(#p629b0f6481)\" d=\"M 101.806979 83.225215 \n",
       "L 103.083984 79.920025 \n",
       "L 104.210754 81.722856 \n",
       "L 163.670344 44.560612 \n",
       "L 163.670344 44.560612 \n",
       "L 104.210754 81.722856 \n",
       "L 105.337523 83.525687 \n",
       "L 101.806979 83.225215 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_3\">\n",
       "    <path clip-path=\"url(#p629b0f6481)\" d=\"M 243.623195 82.353744 \n",
       "L 240.080845 82.436124 \n",
       "L 241.316548 80.70614 \n",
       "L 191.932868 45.432083 \n",
       "L 191.932868 45.432083 \n",
       "L 241.316548 80.70614 \n",
       "L 242.552252 78.976155 \n",
       "L 243.623195 82.353744 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_4\">\n",
       "    <path clip-path=\"url(#p629b0f6481)\" d=\"M 52.654735 135.651365 \n",
       "L 52.765409 132.109787 \n",
       "L 54.425524 133.437879 \n",
       "L 76.759596 105.520288 \n",
       "L 76.759596 105.520288 \n",
       "L 54.425524 133.437879 \n",
       "L 56.085639 134.765971 \n",
       "L 52.654735 135.651365 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_5\">\n",
       "    <path clip-path=\"url(#p629b0f6481)\" d=\"M 122.113927 135.651365 \n",
       "L 118.683023 134.765971 \n",
       "L 120.343138 133.437879 \n",
       "L 98.009065 105.520288 \n",
       "L 98.009065 105.520288 \n",
       "L 120.343138 133.437879 \n",
       "L 122.003252 132.109787 \n",
       "L 122.113927 135.651365 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_6\">\n",
       "    <path clip-path=\"url(#p629b0f6481)\" d=\"M 222.733475 135.651365 \n",
       "L 222.844149 132.109787 \n",
       "L 224.504264 133.437879 \n",
       "L 246.838336 105.520288 \n",
       "L 246.838336 105.520288 \n",
       "L 224.504264 133.437879 \n",
       "L 226.164379 134.765971 \n",
       "L 222.733475 135.651365 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_7\">\n",
       "    <path clip-path=\"url(#p629b0f6481)\" d=\"M 292.192667 135.651365 \n",
       "L 288.761763 134.765971 \n",
       "L 290.421878 133.437879 \n",
       "L 268.087806 105.520288 \n",
       "L 268.087806 105.520288 \n",
       "L 290.421878 133.437879 \n",
       "L 292.081993 132.109787 \n",
       "L 292.192667 135.651365 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_8\">\n",
       "    <path clip-path=\"url(#p629b0f6481)\" d=\"M 212.10874 165.940157 \n",
       "C 216.619281 165.940157 220.945689 164.148101 224.135123 160.958667 \n",
       "C 227.324557 157.769232 229.116614 153.442824 229.116614 148.932283 \n",
       "C 229.116614 144.421743 227.324557 140.095334 224.135123 136.9059 \n",
       "C 220.945689 133.716466 216.619281 131.924409 212.10874 131.924409 \n",
       "C 207.598199 131.924409 203.271791 133.716466 200.082357 136.9059 \n",
       "C 196.892923 140.095334 195.100866 144.421743 195.100866 148.932283 \n",
       "C 195.100866 153.442824 196.892923 157.769232 200.082357 160.958667 \n",
       "C 203.271791 164.148101 207.598199 165.940157 212.10874 165.940157 \n",
       "L 212.10874 165.940157 \n",
       "z\n",
       "\" style=\"fill:none;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_9\">\n",
       "    <path clip-path=\"url(#p629b0f6481)\" d=\"M 87.384331 109.247244 \n",
       "C 91.894872 109.247244 96.22128 107.455187 99.410714 104.265753 \n",
       "C 102.600148 101.076319 104.392205 96.749911 104.392205 92.23937 \n",
       "C 104.392205 87.728829 102.600148 83.402421 99.410714 80.212987 \n",
       "C 96.22128 77.023553 91.894872 75.231496 87.384331 75.231496 \n",
       "C 82.87379 75.231496 78.547382 77.023553 75.357948 80.212987 \n",
       "C 72.168514 83.402421 70.376457 87.728829 70.376457 92.23937 \n",
       "C 70.376457 96.749911 72.168514 101.076319 75.357948 104.265753 \n",
       "C 78.547382 107.455187 82.87379 109.247244 87.384331 109.247244 \n",
       "L 87.384331 109.247244 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_10\">\n",
       "    <path clip-path=\"url(#p629b0f6481)\" d=\"M 257.463071 109.247244 \n",
       "C 261.973612 109.247244 266.30002 107.455187 269.489454 104.265753 \n",
       "C 272.678888 101.076319 274.470945 96.749911 274.470945 92.23937 \n",
       "C 274.470945 87.728829 272.678888 83.402421 269.489454 80.212987 \n",
       "C 266.30002 77.023553 261.973612 75.231496 257.463071 75.231496 \n",
       "C 252.95253 75.231496 248.626122 77.023553 245.436688 80.212987 \n",
       "C 242.247254 83.402421 240.455197 87.728829 240.455197 92.23937 \n",
       "C 240.455197 96.749911 242.247254 101.076319 245.436688 104.265753 \n",
       "C 248.626122 107.455187 252.95253 109.247244 257.463071 109.247244 \n",
       "L 257.463071 109.247244 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_11\">\n",
       "    <path clip-path=\"url(#p629b0f6481)\" d=\"M 178.092992 52.554331 \n",
       "C 182.603533 52.554331 186.929941 50.762274 190.119375 47.57284 \n",
       "C 193.308809 44.383406 195.100866 40.056998 195.100866 35.546457 \n",
       "C 195.100866 31.035916 193.308809 26.709508 190.119375 23.520074 \n",
       "C 186.929941 20.33064 182.603533 18.538583 178.092992 18.538583 \n",
       "C 173.582451 18.538583 169.256043 20.33064 166.066609 23.520074 \n",
       "C 162.877175 26.709508 161.085118 31.035916 161.085118 35.546457 \n",
       "C 161.085118 40.056998 162.877175 44.383406 166.066609 47.57284 \n",
       "C 169.256043 50.762274 173.582451 52.554331 178.092992 52.554331 \n",
       "L 178.092992 52.554331 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_12\">\n",
       "    <path clip-path=\"url(#p629b0f6481)\" d=\"M 42.03 165.940157 \n",
       "C 46.540541 165.940157 50.866949 164.148101 54.056383 160.958667 \n",
       "C 57.245817 157.769232 59.037874 153.442824 59.037874 148.932283 \n",
       "C 59.037874 144.421743 57.245817 140.095334 54.056383 136.9059 \n",
       "C 50.866949 133.716466 46.540541 131.924409 42.03 131.924409 \n",
       "C 37.519459 131.924409 33.193051 133.716466 30.003617 136.9059 \n",
       "C 26.814183 140.095334 25.022126 144.421743 25.022126 148.932283 \n",
       "C 25.022126 153.442824 26.814183 157.769232 30.003617 160.958667 \n",
       "C 33.193051 164.148101 37.519459 165.940157 42.03 165.940157 \n",
       "L 42.03 165.940157 \n",
       "z\n",
       "\" style=\"fill:none;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_13\">\n",
       "    <path clip-path=\"url(#p629b0f6481)\" d=\"M 132.738661 165.940157 \n",
       "C 137.249202 165.940157 141.57561 164.148101 144.765044 160.958667 \n",
       "C 147.954479 157.769232 149.746535 153.442824 149.746535 148.932283 \n",
       "C 149.746535 144.421743 147.954479 140.095334 144.765044 136.9059 \n",
       "C 141.57561 133.716466 137.249202 131.924409 132.738661 131.924409 \n",
       "C 128.228121 131.924409 123.901712 133.716466 120.712278 136.9059 \n",
       "C 117.522844 140.095334 115.730787 144.421743 115.730787 148.932283 \n",
       "C 115.730787 153.442824 117.522844 157.769232 120.712278 160.958667 \n",
       "C 123.901712 164.148101 128.228121 165.940157 132.738661 165.940157 \n",
       "L 132.738661 165.940157 \n",
       "z\n",
       "\" style=\"fill:none;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_14\">\n",
       "    <path clip-path=\"url(#p629b0f6481)\" d=\"M 302.817402 165.940157 \n",
       "C 307.327942 165.940157 311.654351 164.148101 314.843785 160.958667 \n",
       "C 318.033219 157.769232 319.825276 153.442824 319.825276 148.932283 \n",
       "C 319.825276 144.421743 318.033219 140.095334 314.843785 136.9059 \n",
       "C 311.654351 133.716466 307.327942 131.924409 302.817402 131.924409 \n",
       "C 298.306861 131.924409 293.980453 133.716466 290.791019 136.9059 \n",
       "C 287.601584 140.095334 285.809528 144.421743 285.809528 148.932283 \n",
       "C 285.809528 153.442824 287.601584 157.769232 290.791019 160.958667 \n",
       "C 293.980453 164.148101 298.306861 165.940157 302.817402 165.940157 \n",
       "L 302.817402 165.940157 \n",
       "z\n",
       "\" style=\"fill:none;\"/>\n",
       "   </g>\n",
       "   <g id=\"matplotlib.axis_1\"/>\n",
       "   <g id=\"matplotlib.axis_2\"/>\n",
       "   <g id=\"text_1\">\n",
       "    <!-- $c_1$ -->\n",
       "    <defs>\n",
       "     <path d=\"M 50.296875 37.09375 \n",
       "L 44.59375 31.703125 \n",
       "L 43 31.703125 \n",
       "Q 41.59375 39.203125 33.5 39.203125 \n",
       "Q 27.09375 39.203125 21.046875 33.09375 \n",
       "Q 15 27 15 16.90625 \n",
       "Q 15 11.796875 17.84375 8.9375 \n",
       "Q 20.703125 6.09375 25.296875 6.09375 \n",
       "Q 33.40625 6.09375 40.796875 16.59375 \n",
       "L 46.40625 13.203125 \n",
       "Q 36.796875 -1 22.90625 -1 \n",
       "Q 15.5 -1 11.09375 3.203125 \n",
       "Q 6.703125 7.40625 6.703125 15 \n",
       "Q 6.703125 28 15.890625 37.140625 \n",
       "Q 25.09375 46.296875 35.703125 46.296875 \n",
       "Q 41.203125 46.296875 45.140625 44 \n",
       "Q 49.09375 41.703125 50.296875 37.09375 \n",
       "\" id=\"STIXGeneral-Italic-1d624\"/>\n",
       "     <path d=\"M 30.203125 0 \n",
       "L 22.296875 0 \n",
       "L 22.296875 57 \n",
       "Q 20.09375 56 15.75 53.75 \n",
       "Q 11.40625 51.5 10.796875 51.203125 \n",
       "L 10.796875 58.5 \n",
       "L 28.796875 67.703125 \n",
       "L 30.203125 67.203125 \n",
       "z\n",
       "\" id=\"STIXGeneral-Regular-1d7e3\"/>\n",
       "    </defs>\n",
       "    <g transform=\"translate(125.268661417 65.8597883858)scale(0.18 -0.18)\">\n",
       "     <use transform=\"translate(0.0 0.703125)\" xlink:href=\"#STIXGeneral-Italic-1d624\"/>\n",
       "     <use transform=\"translate(45.59999084472656 -12.885937499999997)scale(0.7)\" xlink:href=\"#STIXGeneral-Regular-1d7e3\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"text_2\">\n",
       "    <!-- $c_2$ -->\n",
       "    <defs>\n",
       "     <path d=\"M 46.90625 7.09375 \n",
       "L 44 0 \n",
       "L 3.5 0 \n",
       "L 3.5 2.09375 \n",
       "L 21 23.5 \n",
       "L 21 23.40625 \n",
       "L 26.59375 30.203125 \n",
       "Q 30.5 34.90625 32.09375 36.953125 \n",
       "Q 33.703125 39 35.203125 41.953125 \n",
       "Q 36.703125 44.90625 36.703125 47.5 \n",
       "Q 36.703125 53.703125 33.34375 57.09375 \n",
       "Q 30 60.5 24.203125 60.5 \n",
       "Q 19.59375 60.5 15.75 56.703125 \n",
       "Q 11.90625 52.90625 10.90625 45.90625 \n",
       "L 3.703125 47.59375 \n",
       "Q 5.296875 56.5 11.1875 62.046875 \n",
       "Q 17.09375 67.59375 24.90625 67.59375 \n",
       "Q 33.59375 67.59375 39.09375 62.1875 \n",
       "Q 44.59375 56.796875 44.59375 49.09375 \n",
       "Q 44.59375 43.5 42.5 39.453125 \n",
       "Q 40.40625 35.40625 33.703125 27 \n",
       "L 17.703125 7.09375 \n",
       "z\n",
       "\" id=\"STIXGeneral-Regular-1d7e4\"/>\n",
       "    </defs>\n",
       "    <g transform=\"translate(210.308031496 65.8597883858)scale(0.18 -0.18)\">\n",
       "     <use transform=\"translate(0.0 0.703125)\" xlink:href=\"#STIXGeneral-Italic-1d624\"/>\n",
       "     <use transform=\"translate(45.59999084472656 -12.885937499999997)scale(0.7)\" xlink:href=\"#STIXGeneral-Regular-1d7e4\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"text_3\">\n",
       "    <!-- $-l$ -->\n",
       "    <defs>\n",
       "     <path d=\"M 62.09375 22 \n",
       "L 6.40625 22 \n",
       "L 6.40625 28.59375 \n",
       "L 62.09375 28.59375 \n",
       "z\n",
       "\" id=\"STIXGeneral-Regular-2212\"/>\n",
       "     <path d=\"M 31.296875 67.90625 \n",
       "L 14.40625 0 \n",
       "L 6.09375 0 \n",
       "L 22.5 66 \n",
       "L 30.5 68.40625 \n",
       "z\n",
       "\" id=\"STIXGeneral-Italic-1d62d\"/>\n",
       "    </defs>\n",
       "    <g transform=\"translate(56.6971653543 122.552701772)scale(0.18 -0.18)\">\n",
       "     <use transform=\"translate(0.0 0.59375)\" xlink:href=\"#STIXGeneral-Regular-2212\"/>\n",
       "     <use transform=\"translate(68.49998474121094 0.59375)\" xlink:href=\"#STIXGeneral-Italic-1d62d\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"text_4\">\n",
       "    <!-- $+l$ -->\n",
       "    <defs>\n",
       "     <path d=\"M 63.59375 22 \n",
       "L 37.5 22 \n",
       "L 37.5 -4.09375 \n",
       "L 30.90625 -4.09375 \n",
       "L 30.90625 22 \n",
       "L 4.796875 22 \n",
       "L 4.796875 28.59375 \n",
       "L 30.90625 28.59375 \n",
       "L 30.90625 54.703125 \n",
       "L 37.5 54.703125 \n",
       "L 37.5 28.59375 \n",
       "L 63.59375 28.59375 \n",
       "z\n",
       "\" id=\"STIXGeneral-Regular-2b\"/>\n",
       "    </defs>\n",
       "    <g transform=\"translate(102.051496063 122.552701772)scale(0.18 -0.18)\">\n",
       "     <use transform=\"translate(0.0 0.59375)\" xlink:href=\"#STIXGeneral-Regular-2b\"/>\n",
       "     <use transform=\"translate(68.49998474121094 0.59375)\" xlink:href=\"#STIXGeneral-Italic-1d62d\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"text_5\">\n",
       "    <!-- $-l$ -->\n",
       "    <g transform=\"translate(226.775905512 122.552701772)scale(0.18 -0.18)\">\n",
       "     <use transform=\"translate(0.0 0.59375)\" xlink:href=\"#STIXGeneral-Regular-2212\"/>\n",
       "     <use transform=\"translate(68.49998474121094 0.59375)\" xlink:href=\"#STIXGeneral-Italic-1d62d\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"text_6\">\n",
       "    <!-- $+l$ -->\n",
       "    <g transform=\"translate(272.13023622 122.552701772)scale(0.18 -0.18)\">\n",
       "     <use transform=\"translate(0.0 0.59375)\" xlink:href=\"#STIXGeneral-Regular-2b\"/>\n",
       "     <use transform=\"translate(68.49998474121094 0.59375)\" xlink:href=\"#STIXGeneral-Italic-1d62d\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"text_7\">\n",
       "    <!-- $(0.8,0.2)$ -->\n",
       "    <defs>\n",
       "     <path d=\"M 47.703125 33 \n",
       "Q 47.703125 23.796875 45.546875 16.34375 \n",
       "Q 43.40625 8.90625 38.09375 3.75 \n",
       "Q 32.796875 -1.40625 25 -1.40625 \n",
       "Q 18.796875 -1.40625 14.25 1.6875 \n",
       "Q 9.703125 4.796875 7.203125 10.046875 \n",
       "Q 4.703125 15.296875 3.5 21.140625 \n",
       "Q 2.296875 27 2.296875 33.59375 \n",
       "Q 2.296875 42.90625 4.59375 50.34375 \n",
       "Q 6.90625 57.796875 12.296875 62.6875 \n",
       "Q 17.703125 67.59375 25.40625 67.59375 \n",
       "Q 35.203125 67.59375 41.453125 57.9375 \n",
       "Q 47.703125 48.296875 47.703125 33 \n",
       "M 39.796875 33 \n",
       "Q 39.796875 45.203125 35.75 52.84375 \n",
       "Q 31.703125 60.5 25.203125 60.5 \n",
       "Q 17.796875 60.5 14 52.75 \n",
       "Q 10.203125 45 10.203125 33.40625 \n",
       "Q 10.203125 28.203125 10.953125 23.546875 \n",
       "Q 11.703125 18.90625 13.34375 14.75 \n",
       "Q 15 10.59375 18 8.140625 \n",
       "Q 21 5.703125 25 5.703125 \n",
       "Q 30.09375 5.703125 33.546875 9.796875 \n",
       "Q 37 13.90625 38.390625 19.84375 \n",
       "Q 39.796875 25.796875 39.796875 33 \n",
       "\" id=\"STIXGeneral-Regular-1d7e2\"/>\n",
       "     <path d=\"M 8.296875 -14.09375 \n",
       "L 7.296875 -12.203125 \n",
       "Q 15.59375 -6.59375 15.59375 -1.5 \n",
       "Q 15.59375 -0.203125 14.203125 -0.203125 \n",
       "Q 13.796875 -0.203125 12.84375 -0.390625 \n",
       "Q 11.90625 -0.59375 11.296875 -0.59375 \n",
       "Q 5.5 -0.59375 5.5 4.5 \n",
       "Q 5.5 7.09375 7.140625 8.640625 \n",
       "Q 8.796875 10.203125 11.5 10.203125 \n",
       "Q 14.90625 10.203125 17.203125 7.75 \n",
       "Q 19.5 5.296875 19.5 1.5 \n",
       "Q 19.5 -3.09375 16.453125 -7.390625 \n",
       "Q 13.40625 -11.703125 8.296875 -14.09375 \n",
       "\" id=\"STIXGeneral-Regular-2c\"/>\n",
       "     <path d=\"M 44.703125 16.09375 \n",
       "Q 44.703125 8.796875 39.390625 3.6875 \n",
       "Q 34.09375 -1.40625 24.796875 -1.40625 \n",
       "Q 16.296875 -1.40625 10.59375 3.4375 \n",
       "Q 4.90625 8.296875 4.90625 15.40625 \n",
       "Q 4.90625 20.796875 7.75 25.25 \n",
       "Q 10.59375 29.703125 17.703125 34.5 \n",
       "Q 6 41.40625 6 51.40625 \n",
       "Q 6 58.59375 11.546875 63.09375 \n",
       "Q 17.09375 67.59375 25.59375 67.59375 \n",
       "Q 32.90625 67.59375 37.796875 62.84375 \n",
       "Q 42.703125 58.09375 42.703125 52 \n",
       "Q 42.703125 46.40625 40.09375 42.703125 \n",
       "Q 37.5 39 31.09375 35.296875 \n",
       "Q 44.703125 27 44.703125 16.09375 \n",
       "M 35.5 51.5 \n",
       "Q 35.5 55.5 32.390625 58 \n",
       "Q 29.296875 60.5 24.40625 60.5 \n",
       "Q 19.796875 60.5 16.84375 57.84375 \n",
       "Q 13.90625 55.203125 13.90625 51.796875 \n",
       "Q 13.90625 47.5 16.34375 44.84375 \n",
       "Q 18.796875 42.203125 24.90625 39.40625 \n",
       "Q 35.5 45.203125 35.5 51.5 \n",
       "M 27.59375 28.59375 \n",
       "L 24.09375 30.5 \n",
       "Q 18.90625 28.703125 15.84375 24.640625 \n",
       "Q 12.796875 20.59375 12.796875 16.296875 \n",
       "Q 12.796875 11.796875 16 8.75 \n",
       "Q 19.203125 5.703125 25.203125 5.703125 \n",
       "Q 29.796875 5.703125 33.296875 8.453125 \n",
       "Q 36.796875 11.203125 36.796875 15.796875 \n",
       "Q 36.796875 20 34.6875 22.953125 \n",
       "Q 32.59375 25.90625 27.59375 28.59375 \n",
       "\" id=\"STIXGeneral-Regular-1d7ea\"/>\n",
       "     <path d=\"M 18.09375 4.296875 \n",
       "Q 18.09375 2.09375 16.4375 0.5 \n",
       "Q 14.796875 -1.09375 12.5 -1.09375 \n",
       "Q 10.203125 -1.09375 8.59375 0.5 \n",
       "Q 7 2.09375 7 4.390625 \n",
       "Q 7 6.703125 8.640625 8.34375 \n",
       "Q 10.296875 10 12.59375 10 \n",
       "Q 14.796875 10 16.4375 8.296875 \n",
       "Q 18.09375 6.59375 18.09375 4.296875 \n",
       "\" id=\"STIXGeneral-Regular-2e\"/>\n",
       "     <path d=\"M 30.40625 -16.09375 \n",
       "L 29.203125 -17.703125 \n",
       "Q 17.59375 -11.09375 11.1875 0.5 \n",
       "Q 4.796875 12.09375 4.796875 25.203125 \n",
       "Q 4.796875 52.90625 29.5 67.59375 \n",
       "L 30.40625 66 \n",
       "Q 20.203125 57.296875 16.796875 48.84375 \n",
       "Q 13.40625 40.40625 13.40625 25.5 \n",
       "Q 13.40625 10.703125 16.90625 1.5 \n",
       "Q 20.40625 -7.703125 30.40625 -16.09375 \n",
       "\" id=\"STIXGeneral-Regular-28\"/>\n",
       "     <path d=\"M 2.90625 66 \n",
       "L 4.09375 67.59375 \n",
       "Q 15.5 60.796875 22 49.1875 \n",
       "Q 28.5 37.59375 28.5 24.703125 \n",
       "Q 28.5 -2.59375 3.796875 -17.703125 \n",
       "L 2.90625 -16.09375 \n",
       "Q 13.203125 -7.59375 16.546875 0.84375 \n",
       "Q 19.90625 9.296875 19.90625 24.40625 \n",
       "Q 19.90625 39.59375 16.546875 48.75 \n",
       "Q 13.203125 57.90625 2.90625 66 \n",
       "\" id=\"STIXGeneral-Regular-29\"/>\n",
       "    </defs>\n",
       "    <g transform=\"translate(177.278740157 153.899158465)scale(0.18 -0.18)\">\n",
       "     <use transform=\"translate(0.0 0.40625)\" xlink:href=\"#STIXGeneral-Regular-28\"/>\n",
       "     <use transform=\"translate(33.29998779296875 0.40625)\" xlink:href=\"#STIXGeneral-Regular-1d7e2\"/>\n",
       "     <use transform=\"translate(83.29997253417969 0.40625)\" xlink:href=\"#STIXGeneral-Regular-2e\"/>\n",
       "     <use transform=\"translate(123.41995544433594 0.40625)\" xlink:href=\"#STIXGeneral-Regular-1d7ea\"/>\n",
       "     <use transform=\"translate(173.41994018554686 0.40625)\" xlink:href=\"#STIXGeneral-Regular-2c\"/>\n",
       "     <use transform=\"translate(213.5399230957031 0.40625)\" xlink:href=\"#STIXGeneral-Regular-1d7e2\"/>\n",
       "     <use transform=\"translate(263.53990783691404 0.40625)\" xlink:href=\"#STIXGeneral-Regular-2e\"/>\n",
       "     <use transform=\"translate(303.6598907470703 0.40625)\" xlink:href=\"#STIXGeneral-Regular-1d7e4\"/>\n",
       "     <use transform=\"translate(353.6598754882812 0.40625)\" xlink:href=\"#STIXGeneral-Regular-29\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"text_8\">\n",
       "    <!-- $L_1$ -->\n",
       "    <defs>\n",
       "     <path d=\"M 56.40625 7.40625 \n",
       "L 52.796875 0 \n",
       "L 7.40625 0 \n",
       "L 23.90625 66.203125 \n",
       "L 32.59375 66.203125 \n",
       "L 17.90625 7.40625 \n",
       "z\n",
       "\" id=\"STIXGeneral-Italic-1d613\"/>\n",
       "    </defs>\n",
       "    <g transform=\"translate(78.9243307087 97.2062450787)scale(0.18 -0.18)\">\n",
       "     <use transform=\"translate(0.0 0.796875)\" xlink:href=\"#STIXGeneral-Italic-1d613\"/>\n",
       "     <use transform=\"translate(55.899993896484375 -12.792187499999997)scale(0.7)\" xlink:href=\"#STIXGeneral-Regular-1d7e3\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"text_9\">\n",
       "    <!-- $L_2$ -->\n",
       "    <g transform=\"translate(249.003070866 97.2062450787)scale(0.18 -0.18)\">\n",
       "     <use transform=\"translate(0.0 0.796875)\" xlink:href=\"#STIXGeneral-Italic-1d613\"/>\n",
       "     <use transform=\"translate(55.899993896484375 -12.792187499999997)scale(0.7)\" xlink:href=\"#STIXGeneral-Regular-1d7e4\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"text_10\">\n",
       "    <!-- $C$ -->\n",
       "    <defs>\n",
       "     <path d=\"M 75.5 55.40625 \n",
       "L 72.90625 45.296875 \n",
       "L 71 45.296875 \n",
       "Q 70.203125 50.796875 66.890625 54.25 \n",
       "Q 63.59375 57.703125 59.75 58.84375 \n",
       "Q 55.90625 60 51.296875 60 \n",
       "Q 38 60 28.34375 49.390625 \n",
       "Q 18.703125 38.796875 18.703125 24.703125 \n",
       "Q 18.703125 16 23.75 11.09375 \n",
       "Q 28.796875 6.203125 38.203125 6.203125 \n",
       "Q 50.5 6.203125 62.796875 17 \n",
       "L 66.59375 11.90625 \n",
       "Q 53 -1.40625 36 -1.40625 \n",
       "Q 23.203125 -1.40625 16.390625 5.140625 \n",
       "Q 9.59375 11.703125 9.59375 22.796875 \n",
       "Q 9.59375 34.703125 15.546875 45.046875 \n",
       "Q 21.5 55.40625 31.546875 61.5 \n",
       "Q 41.59375 67.59375 53.09375 67.59375 \n",
       "Q 60.59375 67.59375 66.75 64.640625 \n",
       "Q 72.90625 61.703125 75.5 55.40625 \n",
       "\" id=\"STIXGeneral-Italic-1d60a\"/>\n",
       "    </defs>\n",
       "    <g transform=\"translate(171.972992126 40.5133316929)scale(0.18 -0.18)\">\n",
       "     <use transform=\"translate(0.0 0.40625)\" xlink:href=\"#STIXGeneral-Italic-1d60a\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"text_11\">\n",
       "    <!-- $(0.9,0.1)$ -->\n",
       "    <defs>\n",
       "     <path d=\"M 5.5 -0.203125 \n",
       "L 6.796875 4.703125 \n",
       "Q 18.203125 5.5 26.140625 11.25 \n",
       "Q 34.09375 17 37.59375 27.5 \n",
       "Q 31.796875 23.09375 23.90625 23.09375 \n",
       "Q 15.296875 23.09375 9.046875 28.890625 \n",
       "Q 2.796875 34.703125 2.796875 44.203125 \n",
       "Q 2.796875 53.90625 8.84375 60.75 \n",
       "Q 14.90625 67.59375 24.203125 67.59375 \n",
       "Q 30.09375 67.59375 34.5 65.34375 \n",
       "Q 38.90625 63.09375 41.5 59.09375 \n",
       "Q 44.09375 55.09375 45.34375 50.25 \n",
       "Q 46.59375 45.40625 46.59375 39.796875 \n",
       "Q 46.59375 31.40625 43.546875 23.203125 \n",
       "Q 40.5 15 35.5 10.09375 \n",
       "Q 28.796875 3.59375 22.84375 1.296875 \n",
       "Q 16.90625 -1 5.703125 -2.09375 \n",
       "z\n",
       "M 38.59375 42.203125 \n",
       "Q 38.5 50.296875 34.546875 55.390625 \n",
       "Q 30.59375 60.5 23.90625 60.5 \n",
       "Q 18.40625 60.5 14.59375 56.296875 \n",
       "Q 10.796875 52.09375 10.796875 45.59375 \n",
       "Q 10.796875 38.40625 14.890625 34.34375 \n",
       "Q 19 30.296875 24.703125 30.296875 \n",
       "Q 29.90625 30.296875 33.796875 33.34375 \n",
       "Q 37.703125 36.40625 38.59375 42.203125 \n",
       "\" id=\"STIXGeneral-Regular-1d7eb\"/>\n",
       "    </defs>\n",
       "    <g transform=\"translate(7.2 153.899158465)scale(0.18 -0.18)\">\n",
       "     <use transform=\"translate(0.0 0.296875)\" xlink:href=\"#STIXGeneral-Regular-28\"/>\n",
       "     <use transform=\"translate(33.29998779296875 0.296875)\" xlink:href=\"#STIXGeneral-Regular-1d7e2\"/>\n",
       "     <use transform=\"translate(83.29997253417969 0.296875)\" xlink:href=\"#STIXGeneral-Regular-2e\"/>\n",
       "     <use transform=\"translate(123.41995544433594 0.296875)\" xlink:href=\"#STIXGeneral-Regular-1d7eb\"/>\n",
       "     <use transform=\"translate(173.41994018554686 0.296875)\" xlink:href=\"#STIXGeneral-Regular-2c\"/>\n",
       "     <use transform=\"translate(213.5399230957031 0.296875)\" xlink:href=\"#STIXGeneral-Regular-1d7e2\"/>\n",
       "     <use transform=\"translate(263.53990783691404 0.296875)\" xlink:href=\"#STIXGeneral-Regular-2e\"/>\n",
       "     <use transform=\"translate(303.6598907470703 0.296875)\" xlink:href=\"#STIXGeneral-Regular-1d7e3\"/>\n",
       "     <use transform=\"translate(353.6598754882812 0.296875)\" xlink:href=\"#STIXGeneral-Regular-29\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"text_12\">\n",
       "    <!-- $(0.3,0.7)$ -->\n",
       "    <defs>\n",
       "     <path d=\"M 45.09375 64.203125 \n",
       "L 23 -0.796875 \n",
       "L 14.796875 -0.796875 \n",
       "L 35.40625 59.09375 \n",
       "L 3.796875 59.09375 \n",
       "L 6.90625 66.203125 \n",
       "L 45.09375 66.203125 \n",
       "z\n",
       "\" id=\"STIXGeneral-Regular-1d7e9\"/>\n",
       "     <path d=\"M 11.296875 49.203125 \n",
       "L 4.203125 50.90625 \n",
       "Q 6.40625 58.703125 11.5 63.140625 \n",
       "Q 16.59375 67.59375 24.296875 67.59375 \n",
       "Q 31.40625 67.59375 36.203125 63.09375 \n",
       "Q 41 58.59375 41 51.90625 \n",
       "Q 41 43 32.40625 37 \n",
       "Q 38 35 41.046875 30.34375 \n",
       "Q 44.09375 25.703125 44.09375 21 \n",
       "Q 44.09375 11.296875 37.796875 5 \n",
       "Q 31.40625 -1.40625 20.5 -1.40625 \n",
       "Q 9.5 -1.40625 3.09375 5.59375 \n",
       "L 7.796875 11.203125 \n",
       "Q 12.90625 5.703125 20 5.703125 \n",
       "Q 27.40625 5.703125 31.59375 9.296875 \n",
       "Q 36.203125 13.203125 36.203125 19.09375 \n",
       "Q 36.203125 24.296875 32.453125 27.796875 \n",
       "Q 28.703125 31.296875 22.203125 32.203125 \n",
       "L 15.796875 32.203125 \n",
       "L 15.796875 34.296875 \n",
       "L 20.59375 39.40625 \n",
       "Q 25.09375 39.40625 29.09375 42.84375 \n",
       "Q 33.09375 46.296875 33.09375 51.203125 \n",
       "Q 33.09375 55.40625 30.4375 57.953125 \n",
       "Q 27.796875 60.5 24 60.5 \n",
       "Q 20 60.5 16.546875 57.640625 \n",
       "Q 13.09375 54.796875 11.296875 49.203125 \n",
       "\" id=\"STIXGeneral-Regular-1d7e5\"/>\n",
       "    </defs>\n",
       "    <g transform=\"translate(97.9086614173 153.899158465)scale(0.18 -0.18)\">\n",
       "     <use transform=\"translate(0.0 0.40625)\" xlink:href=\"#STIXGeneral-Regular-28\"/>\n",
       "     <use transform=\"translate(33.29998779296875 0.40625)\" xlink:href=\"#STIXGeneral-Regular-1d7e2\"/>\n",
       "     <use transform=\"translate(83.29997253417969 0.40625)\" xlink:href=\"#STIXGeneral-Regular-2e\"/>\n",
       "     <use transform=\"translate(123.41995544433594 0.40625)\" xlink:href=\"#STIXGeneral-Regular-1d7e5\"/>\n",
       "     <use transform=\"translate(173.41994018554686 0.40625)\" xlink:href=\"#STIXGeneral-Regular-2c\"/>\n",
       "     <use transform=\"translate(213.5399230957031 0.40625)\" xlink:href=\"#STIXGeneral-Regular-1d7e2\"/>\n",
       "     <use transform=\"translate(263.53990783691404 0.40625)\" xlink:href=\"#STIXGeneral-Regular-2e\"/>\n",
       "     <use transform=\"translate(303.6598907470703 0.40625)\" xlink:href=\"#STIXGeneral-Regular-1d7e9\"/>\n",
       "     <use transform=\"translate(353.6598754882812 0.40625)\" xlink:href=\"#STIXGeneral-Regular-29\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"text_13\">\n",
       "    <!-- $(0.1,0.9)$ -->\n",
       "    <g transform=\"translate(267.987401575 153.899158465)scale(0.18 -0.18)\">\n",
       "     <use transform=\"translate(0.0 0.296875)\" xlink:href=\"#STIXGeneral-Regular-28\"/>\n",
       "     <use transform=\"translate(33.29998779296875 0.296875)\" xlink:href=\"#STIXGeneral-Regular-1d7e2\"/>\n",
       "     <use transform=\"translate(83.29997253417969 0.296875)\" xlink:href=\"#STIXGeneral-Regular-2e\"/>\n",
       "     <use transform=\"translate(123.41995544433594 0.296875)\" xlink:href=\"#STIXGeneral-Regular-1d7e3\"/>\n",
       "     <use transform=\"translate(173.41994018554686 0.296875)\" xlink:href=\"#STIXGeneral-Regular-2c\"/>\n",
       "     <use transform=\"translate(213.5399230957031 0.296875)\" xlink:href=\"#STIXGeneral-Regular-1d7e2\"/>\n",
       "     <use transform=\"translate(263.53990783691404 0.296875)\" xlink:href=\"#STIXGeneral-Regular-2e\"/>\n",
       "     <use transform=\"translate(303.6598907470703 0.296875)\" xlink:href=\"#STIXGeneral-Regular-1d7eb\"/>\n",
       "     <use transform=\"translate(353.6598754882812 0.296875)\" xlink:href=\"#STIXGeneral-Regular-29\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "  </g>\n",
       " </g>\n",
       " <defs>\n",
       "  <clipPath id=\"p629b0f6481\">\n",
       "   <rect height=\"170.078740157\" width=\"340.157480315\" x=\"13.6835433071\" y=\"7.2\"/>\n",
       "  </clipPath>\n",
       " </defs>\n",
       "</svg>\n"
      ],
      "text/plain": [
       "<matplotlib.figure.Figure at 0x7feb96c2d518>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "pgm = daft.PGM([6, 3], origin=[-0.5, 0.5])\n",
    "add_node(pgm, 'c', '$C$', 2.4, 3)\n",
    "add_node(pgm, 'l1', '$L_1$', 0.8, 2)\n",
    "add_node(pgm, 'l2', '$L_2$', 3.8, 2)\n",
    "add_node(pgm, 't1', '$(0.9,0.1)$', 0, 1, plot_params={'edgecolor': 'none'})\n",
    "add_node(pgm, 't2', '$(0.3,0.7)$', 1.6, 1, plot_params={'edgecolor': 'none'})\n",
    "add_node(pgm, 't3', '$(0.8,0.2)$', 3, 1, plot_params={'edgecolor': 'none'})\n",
    "add_node(pgm, 't4', '$(0.1,0.9)$', 4.6, 1, plot_params={'edgecolor': 'none'})\n",
    "add_edges(pgm, [\n",
    "        ('c', 'l1', '$c_1$'),\n",
    "        ('c', 'l2', '$c_2$'),\n",
    "        ('l1', 't1', '$-l$'),\n",
    "        ('l1', 't2', '$+l$'),\n",
    "        ('l2', 't3', '$-l$'),\n",
    "        ('l2', 't4', '$+l$')\n",
    "\n",
    "    ])\n",
    "pgm.render()\n",
    "save('bn_tree_cpd_03')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 45,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "image/svg+xml": [
       "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"no\"?>\n",
       "<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\n",
       "  \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n",
       "<!-- Created with matplotlib (http://matplotlib.org/) -->\n",
       "<svg height=\"127pt\" version=\"1.1\" viewBox=\"0 0 156 127\" width=\"156pt\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n",
       " <defs>\n",
       "  <style type=\"text/css\">\n",
       "*{stroke-linecap:butt;stroke-linejoin:round;stroke-miterlimit:100000;}\n",
       "  </style>\n",
       " </defs>\n",
       " <g id=\"figure_1\">\n",
       "  <g id=\"patch_1\">\n",
       "   <path d=\"M 0 127.785827 \n",
       "L 156.132283 127.785827 \n",
       "L 156.132283 0 \n",
       "L 0 0 \n",
       "L 0 127.785827 \n",
       "z\n",
       "\" style=\"fill:none;\"/>\n",
       "  </g>\n",
       "  <g id=\"axes_1\">\n",
       "   <g id=\"patch_2\">\n",
       "    <path clip-path=\"url(#p8c828bf449)\" d=\"M 68.874404 68.874404 \n",
       "L 65.366709 68.373305 \n",
       "L 66.870007 66.870007 \n",
       "L 47.57284 47.57284 \n",
       "L 47.57284 47.57284 \n",
       "L 66.870007 66.870007 \n",
       "L 68.373305 65.366709 \n",
       "L 68.874404 68.874404 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_3\">\n",
       "    <path clip-path=\"url(#p8c828bf449)\" d=\"M 80.900787 63.892913 \n",
       "L 78.774803 61.058268 \n",
       "L 80.900787 61.058268 \n",
       "L 80.900787 52.554331 \n",
       "L 80.900787 52.554331 \n",
       "L 80.900787 61.058268 \n",
       "L 83.026772 61.058268 \n",
       "L 80.900787 63.892913 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_4\">\n",
       "    <path clip-path=\"url(#p8c828bf449)\" d=\"M 92.92717 68.874404 \n",
       "L 93.42827 65.366709 \n",
       "L 94.931568 66.870007 \n",
       "L 114.228735 47.57284 \n",
       "L 114.228735 47.57284 \n",
       "L 94.931568 66.870007 \n",
       "L 96.434866 68.373305 \n",
       "L 92.92717 68.874404 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_5\">\n",
       "    <path clip-path=\"url(#p8c828bf449)\" d=\"M 63.892913 80.900787 \n",
       "L 61.058268 83.026772 \n",
       "L 61.058268 80.900787 \n",
       "L 52.554331 80.900787 \n",
       "L 52.554331 80.900787 \n",
       "L 61.058268 80.900787 \n",
       "L 61.058268 78.774803 \n",
       "L 63.892913 80.900787 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_6\">\n",
       "    <path clip-path=\"url(#p8c828bf449)\" d=\"M 126.255118 52.554331 \n",
       "C 130.765659 52.554331 135.092067 50.762274 138.281501 47.57284 \n",
       "C 141.470935 44.383406 143.262992 40.056998 143.262992 35.546457 \n",
       "C 143.262992 31.035916 141.470935 26.709508 138.281501 23.520074 \n",
       "C 135.092067 20.33064 130.765659 18.538583 126.255118 18.538583 \n",
       "C 121.744577 18.538583 117.418169 20.33064 114.228735 23.520074 \n",
       "C 111.039301 26.709508 109.247244 31.035916 109.247244 35.546457 \n",
       "C 109.247244 40.056998 111.039301 44.383406 114.228735 47.57284 \n",
       "C 117.418169 50.762274 121.744577 52.554331 126.255118 52.554331 \n",
       "L 126.255118 52.554331 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_7\">\n",
       "    <path clip-path=\"url(#p8c828bf449)\" d=\"M 80.900787 52.554331 \n",
       "C 85.411328 52.554331 89.737736 50.762274 92.92717 47.57284 \n",
       "C 96.116605 44.383406 97.908661 40.056998 97.908661 35.546457 \n",
       "C 97.908661 31.035916 96.116605 26.709508 92.92717 23.520074 \n",
       "C 89.737736 20.33064 85.411328 18.538583 80.900787 18.538583 \n",
       "C 76.390246 18.538583 72.063838 20.33064 68.874404 23.520074 \n",
       "C 65.68497 26.709508 63.892913 31.035916 63.892913 35.546457 \n",
       "C 63.892913 40.056998 65.68497 44.383406 68.874404 47.57284 \n",
       "C 72.063838 50.762274 76.390246 52.554331 80.900787 52.554331 \n",
       "L 80.900787 52.554331 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_8\">\n",
       "    <path clip-path=\"url(#p8c828bf449)\" d=\"M 80.900787 96.207874 \n",
       "C 84.960274 96.207874 88.854041 94.595023 91.724532 91.724532 \n",
       "C 94.595023 88.854041 96.207874 84.960274 96.207874 80.900787 \n",
       "C 96.207874 76.841301 94.595023 72.947533 91.724532 70.077043 \n",
       "C 88.854041 67.206552 84.960274 65.593701 80.900787 65.593701 \n",
       "C 76.841301 65.593701 72.947533 67.206552 70.077043 70.077043 \n",
       "C 67.206552 72.947533 65.593701 76.841301 65.593701 80.900787 \n",
       "C 65.593701 84.960274 67.206552 88.854041 70.077043 91.724532 \n",
       "C 72.947533 94.595023 76.841301 96.207874 80.900787 96.207874 \n",
       "L 80.900787 96.207874 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_9\">\n",
       "    <path clip-path=\"url(#p8c828bf449)\" d=\"M 80.900787 97.908661 \n",
       "C 85.411328 97.908661 89.737736 96.116605 92.92717 92.92717 \n",
       "C 96.116605 89.737736 97.908661 85.411328 97.908661 80.900787 \n",
       "C 97.908661 76.390246 96.116605 72.063838 92.92717 68.874404 \n",
       "C 89.737736 65.68497 85.411328 63.892913 80.900787 63.892913 \n",
       "C 76.390246 63.892913 72.063838 65.68497 68.874404 68.874404 \n",
       "C 65.68497 72.063838 63.892913 76.390246 63.892913 80.900787 \n",
       "C 63.892913 85.411328 65.68497 89.737736 68.874404 92.92717 \n",
       "C 72.063838 96.116605 76.390246 97.908661 80.900787 97.908661 \n",
       "L 80.900787 97.908661 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_10\">\n",
       "    <path clip-path=\"url(#p8c828bf449)\" d=\"M 35.546457 97.908661 \n",
       "C 40.056998 97.908661 44.383406 96.116605 47.57284 92.92717 \n",
       "C 50.762274 89.737736 52.554331 85.411328 52.554331 80.900787 \n",
       "C 52.554331 76.390246 50.762274 72.063838 47.57284 68.874404 \n",
       "C 44.383406 65.68497 40.056998 63.892913 35.546457 63.892913 \n",
       "C 31.035916 63.892913 26.709508 65.68497 23.520074 68.874404 \n",
       "C 20.33064 72.063838 18.538583 76.390246 18.538583 80.900787 \n",
       "C 18.538583 85.411328 20.33064 89.737736 23.520074 92.92717 \n",
       "C 26.709508 96.116605 31.035916 97.908661 35.546457 97.908661 \n",
       "L 35.546457 97.908661 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_11\">\n",
       "    <path clip-path=\"url(#p8c828bf449)\" d=\"M 35.546457 52.554331 \n",
       "C 40.056998 52.554331 44.383406 50.762274 47.57284 47.57284 \n",
       "C 50.762274 44.383406 52.554331 40.056998 52.554331 35.546457 \n",
       "C 52.554331 31.035916 50.762274 26.709508 47.57284 23.520074 \n",
       "C 44.383406 20.33064 40.056998 18.538583 35.546457 18.538583 \n",
       "C 31.035916 18.538583 26.709508 20.33064 23.520074 23.520074 \n",
       "C 20.33064 26.709508 18.538583 31.035916 18.538583 35.546457 \n",
       "C 18.538583 40.056998 20.33064 44.383406 23.520074 47.57284 \n",
       "C 26.709508 50.762274 31.035916 52.554331 35.546457 52.554331 \n",
       "L 35.546457 52.554331 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"matplotlib.axis_1\"/>\n",
       "   <g id=\"matplotlib.axis_2\"/>\n",
       "   <g id=\"text_1\">\n",
       "    <!-- $z_n$ -->\n",
       "    <defs>\n",
       "     <path d=\"M 25.09375 45.90625 \n",
       "L 23.90625 40.203125 \n",
       "Q 28.40625 43.796875 32.203125 45.046875 \n",
       "Q 36 46.296875 40.5 46.296875 \n",
       "Q 45.203125 46.296875 48.09375 43.75 \n",
       "Q 51 41.203125 51 37.203125 \n",
       "Q 51 34.796875 50.40625 32.09375 \n",
       "L 42.40625 0 \n",
       "L 34.5 0 \n",
       "L 42 30.40625 \n",
       "Q 42.5 32.59375 42.5 33.90625 \n",
       "Q 42.5 39.203125 36 39.203125 \n",
       "Q 33.09375 39.203125 28.640625 36.703125 \n",
       "Q 24.203125 34.203125 21.703125 30.203125 \n",
       "L 14.203125 0 \n",
       "L 6.296875 0 \n",
       "L 17.203125 44 \n",
       "L 24.296875 46.40625 \n",
       "z\n",
       "\" id=\"STIXGeneral-Italic-1d62f\"/>\n",
       "     <path d=\"M 51.703125 45.296875 \n",
       "L 51.203125 43.296875 \n",
       "L 17 7.09375 \n",
       "L 43.40625 7.09375 \n",
       "L 40.703125 0 \n",
       "L 2.5 0 \n",
       "L 2.90625 2 \n",
       "L 37.09375 38.203125 \n",
       "L 14.40625 38.203125 \n",
       "L 17.296875 45.296875 \n",
       "z\n",
       "\" id=\"STIXGeneral-Italic-1d63b\"/>\n",
       "    </defs>\n",
       "    <g transform=\"translate(118.87511811 40.5133316929)scale(0.18 -0.18)\">\n",
       "     <use transform=\"translate(0.0 0.703125)\" xlink:href=\"#STIXGeneral-Italic-1d63b\"/>\n",
       "     <use transform=\"translate(44.69999694824219 -12.885937499999997)scale(0.7)\" xlink:href=\"#STIXGeneral-Italic-1d62f\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"text_2\">\n",
       "    <!-- $\\dots$ -->\n",
       "    <defs>\n",
       "     <path d=\"M 88.796875 4.296875 \n",
       "Q 88.796875 2.09375 87.140625 0.5 \n",
       "Q 85.5 -1.09375 83.203125 -1.09375 \n",
       "Q 80.90625 -1.09375 79.296875 0.5 \n",
       "Q 77.703125 2.09375 77.703125 4.390625 \n",
       "Q 77.703125 6.703125 79.34375 8.34375 \n",
       "Q 81 10 83.296875 10 \n",
       "Q 85.5 10 87.140625 8.296875 \n",
       "Q 88.796875 6.59375 88.796875 4.296875 \n",
       "M 55.5 4.296875 \n",
       "Q 55.5 2.09375 53.84375 0.5 \n",
       "Q 52.203125 -1.09375 49.890625 -1.09375 \n",
       "Q 47.59375 -1.09375 46 0.5 \n",
       "Q 44.40625 2.09375 44.40625 4.390625 \n",
       "Q 44.40625 6.703125 46.046875 8.34375 \n",
       "Q 47.703125 10 50 10 \n",
       "Q 52.203125 10 53.84375 8.296875 \n",
       "Q 55.5 6.59375 55.5 4.296875 \n",
       "M 22.203125 4.296875 \n",
       "Q 22.203125 2.09375 20.546875 0.5 \n",
       "Q 18.90625 -1.09375 16.59375 -1.09375 \n",
       "Q 14.296875 -1.09375 12.6875 0.5 \n",
       "Q 11.09375 2.09375 11.09375 4.390625 \n",
       "Q 11.09375 6.703125 12.75 8.34375 \n",
       "Q 14.40625 10 16.703125 10 \n",
       "Q 18.90625 10 20.546875 8.296875 \n",
       "Q 22.203125 6.59375 22.203125 4.296875 \n",
       "\" id=\"STIXGeneral-Regular-2026\"/>\n",
       "    </defs>\n",
       "    <g transform=\"translate(71.9007874016 40.5133316929)scale(0.18 -0.18)\">\n",
       "     <use xlink:href=\"#STIXGeneral-Regular-2026\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"text_3\">\n",
       "    <!-- $Y$ -->\n",
       "    <defs>\n",
       "     <path d=\"M 77.40625 66.203125 \n",
       "L 43 28.796875 \n",
       "L 35.796875 0 \n",
       "L 27.09375 0 \n",
       "L 34.203125 28.796875 \n",
       "L 18.59375 66.203125 \n",
       "L 28.09375 66.203125 \n",
       "L 40.5 36.203125 \n",
       "L 67.90625 66.203125 \n",
       "z\n",
       "\" id=\"STIXGeneral-Italic-1d620\"/>\n",
       "    </defs>\n",
       "    <g transform=\"translate(75.2307874016 85.8676624016)scale(0.18 -0.18)\">\n",
       "     <use transform=\"translate(0.0 0.796875)\" xlink:href=\"#STIXGeneral-Italic-1d620\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"text_4\">\n",
       "    <!-- $A$ -->\n",
       "    <defs>\n",
       "     <path d=\"M 63.5 0 \n",
       "L 53.90625 0 \n",
       "L 50.59375 20 \n",
       "L 25.703125 20 \n",
       "L 12.703125 0 \n",
       "L 3.09375 0 \n",
       "L 48.796875 67.40625 \n",
       "L 51.40625 67.40625 \n",
       "z\n",
       "M 49.5 27.40625 \n",
       "L 45.796875 50.296875 \n",
       "L 30.703125 27.40625 \n",
       "z\n",
       "\" id=\"STIXGeneral-Italic-1d608\"/>\n",
       "    </defs>\n",
       "    <g transform=\"translate(29.5164566929 85.8676624016)scale(0.18 -0.18)\">\n",
       "     <use transform=\"translate(0.0 0.59375)\" xlink:href=\"#STIXGeneral-Italic-1d608\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"text_5\">\n",
       "    <!-- $z_1$ -->\n",
       "    <defs>\n",
       "     <path d=\"M 30.203125 0 \n",
       "L 22.296875 0 \n",
       "L 22.296875 57 \n",
       "Q 20.09375 56 15.75 53.75 \n",
       "Q 11.40625 51.5 10.796875 51.203125 \n",
       "L 10.796875 58.5 \n",
       "L 28.796875 67.703125 \n",
       "L 30.203125 67.203125 \n",
       "z\n",
       "\" id=\"STIXGeneral-Regular-1d7e3\"/>\n",
       "    </defs>\n",
       "    <g transform=\"translate(28.1664566929 40.5133316929)scale(0.18 -0.18)\">\n",
       "     <use transform=\"translate(0.0 0.703125)\" xlink:href=\"#STIXGeneral-Italic-1d63b\"/>\n",
       "     <use transform=\"translate(44.69999694824219 -12.885937499999997)scale(0.7)\" xlink:href=\"#STIXGeneral-Regular-1d7e3\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "  </g>\n",
       " </g>\n",
       " <defs>\n",
       "  <clipPath id=\"p8c828bf449\">\n",
       "   <rect height=\"113.385826772\" width=\"141.732283465\" x=\"7.2\" y=\"7.2\"/>\n",
       "  </clipPath>\n",
       " </defs>\n",
       "</svg>\n"
      ],
      "text/plain": [
       "<matplotlib.figure.Figure at 0x7feb96bfb240>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "pgm = daft.PGM([2.5, 2], origin=[-0.5, 0.5], observed_style='inner')\n",
    "add_node(pgm, 'z1', '$z_1$', 0, 2)\n",
    "add_node(pgm, 'z', r'$\\dots$', 0.8, 2)\n",
    "add_node(pgm, 'zn', '$z_n$', 1.6, 2)\n",
    "add_node(pgm, 'Y', '$Y$', 0.8, 1.2, observed=True)\n",
    "add_node(pgm, 'A', '$A$', 0, 1.2)\n",
    "add_edges(pgm, [\n",
    "        ('z1', 'Y'),\n",
    "        ('z', 'Y'),\n",
    "        ('zn', 'Y'),\n",
    "        ('A', 'Y')\n",
    "    ])\n",
    "pgm.render()\n",
    "save('bn_multiplexer_cpd')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 46,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "image/svg+xml": [
       "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"no\"?>\n",
       "<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\n",
       "  \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n",
       "<!-- Created with matplotlib (http://matplotlib.org/) -->\n",
       "<svg height=\"184pt\" version=\"1.1\" viewBox=\"0 0 241 184\" width=\"241pt\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n",
       " <defs>\n",
       "  <style type=\"text/css\">\n",
       "*{stroke-linecap:butt;stroke-linejoin:round;stroke-miterlimit:100000;}\n",
       "  </style>\n",
       " </defs>\n",
       " <g id=\"figure_1\">\n",
       "  <g id=\"patch_1\">\n",
       "   <path d=\"M 0 184.47874 \n",
       "L 241.171654 184.47874 \n",
       "L 241.171654 0 \n",
       "L 0 0 \n",
       "L 0 184.47874 \n",
       "z\n",
       "\" style=\"fill:none;\"/>\n",
       "  </g>\n",
       "  <g id=\"axes_1\">\n",
       "   <g id=\"patch_2\">\n",
       "    <path clip-path=\"url(#pea50b6e689)\" d=\"M 113.782677 123.987402 \n",
       "L 113.782677 120.444094 \n",
       "L 115.483465 121.719685 \n",
       "L 127.388976 105.845669 \n",
       "L 127.388976 105.845669 \n",
       "L 115.483465 121.719685 \n",
       "L 117.184252 122.995276 \n",
       "L 113.782677 123.987402 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_3\">\n",
       "    <path clip-path=\"url(#pea50b6e689)\" d=\"M 111.184105 122.381396 \n",
       "L 110.550259 118.895243 \n",
       "L 112.451797 119.846012 \n",
       "L 118.648966 107.451675 \n",
       "L 118.648966 107.451675 \n",
       "L 112.451797 119.846012 \n",
       "L 114.353335 120.796781 \n",
       "L 111.184105 122.381396 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_4\">\n",
       "    <path clip-path=\"url(#pea50b6e689)\" d=\"M 117.729359 128.15943 \n",
       "L 118.908643 124.818125 \n",
       "L 120.087927 126.587051 \n",
       "L 157.458042 101.673641 \n",
       "L 157.458042 101.673641 \n",
       "L 120.087927 126.587051 \n",
       "L 121.267211 128.355977 \n",
       "L 117.729359 128.15943 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_5\">\n",
       "    <path clip-path=\"url(#pea50b6e689)\" d=\"M 89.426546 128.15943 \n",
       "L 85.888695 128.355977 \n",
       "L 87.067978 126.587051 \n",
       "L 49.697863 101.673641 \n",
       "L 49.697863 101.673641 \n",
       "L 87.067978 126.587051 \n",
       "L 88.247262 124.818125 \n",
       "L 89.426546 128.15943 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_6\">\n",
       "    <path clip-path=\"url(#pea50b6e689)\" d=\"M 125.567318 80.212987 \n",
       "L 122.059623 79.711888 \n",
       "L 123.562921 78.20859 \n",
       "L 92.92717 47.57284 \n",
       "L 92.92717 47.57284 \n",
       "L 123.562921 78.20859 \n",
       "L 125.066218 76.705292 \n",
       "L 125.567318 80.212987 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_7\">\n",
       "    <path clip-path=\"url(#pea50b6e689)\" d=\"M 126.255118 75.231496 \n",
       "L 124.129134 72.39685 \n",
       "L 126.255118 72.39685 \n",
       "L 126.255118 52.554331 \n",
       "L 126.255118 52.554331 \n",
       "L 126.255118 72.39685 \n",
       "L 128.381102 72.39685 \n",
       "L 126.255118 75.231496 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_8\">\n",
       "    <path clip-path=\"url(#pea50b6e689)\" d=\"M 171.609449 75.231496 \n",
       "L 169.483465 72.39685 \n",
       "L 171.609449 72.39685 \n",
       "L 171.609449 52.554331 \n",
       "L 171.609449 52.554331 \n",
       "L 171.609449 72.39685 \n",
       "L 173.735433 72.39685 \n",
       "L 171.609449 75.231496 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_9\">\n",
       "    <path clip-path=\"url(#pea50b6e689)\" d=\"M 171.609449 109.247244 \n",
       "C 176.11999 109.247244 180.446398 107.455187 183.635832 104.265753 \n",
       "C 186.825266 101.076319 188.617323 96.749911 188.617323 92.23937 \n",
       "C 188.617323 87.728829 186.825266 83.402421 183.635832 80.212987 \n",
       "C 180.446398 77.023553 176.11999 75.231496 171.609449 75.231496 \n",
       "C 167.098908 75.231496 162.7725 77.023553 159.583066 80.212987 \n",
       "C 156.393632 83.402421 154.601575 87.728829 154.601575 92.23937 \n",
       "C 154.601575 96.749911 156.393632 101.076319 159.583066 104.265753 \n",
       "C 162.7725 107.455187 167.098908 109.247244 171.609449 109.247244 \n",
       "L 171.609449 109.247244 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_10\">\n",
       "    <path clip-path=\"url(#pea50b6e689)\" d=\"M 103.577953 152.900787 \n",
       "C 107.63744 152.900787 111.531207 151.287936 114.401698 148.417446 \n",
       "C 117.272188 145.546955 118.885039 141.653188 118.885039 137.593701 \n",
       "C 118.885039 133.534214 117.272188 129.640447 114.401698 126.769956 \n",
       "C 111.531207 123.899465 107.63744 122.286614 103.577953 122.286614 \n",
       "C 99.518466 122.286614 95.624699 123.899465 92.754208 126.769956 \n",
       "C 89.883717 129.640447 88.270866 133.534214 88.270866 137.593701 \n",
       "C 88.270866 141.653188 89.883717 145.546955 92.754208 148.417446 \n",
       "C 95.624699 151.287936 99.518466 152.900787 103.577953 152.900787 \n",
       "L 103.577953 152.900787 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_11\">\n",
       "    <path clip-path=\"url(#pea50b6e689)\" d=\"M 103.577953 154.601575 \n",
       "C 108.088494 154.601575 112.414902 152.809518 115.604336 149.620084 \n",
       "C 118.79377 146.43065 120.585827 142.104242 120.585827 137.593701 \n",
       "C 120.585827 133.08316 118.79377 128.756752 115.604336 125.567318 \n",
       "C 112.414902 122.377884 108.088494 120.585827 103.577953 120.585827 \n",
       "C 99.067412 120.585827 94.741004 122.377884 91.55157 125.567318 \n",
       "C 88.362136 128.756752 86.570079 133.08316 86.570079 137.593701 \n",
       "C 86.570079 142.104242 88.362136 146.43065 91.55157 149.620084 \n",
       "C 94.741004 152.809518 99.067412 154.601575 103.577953 154.601575 \n",
       "L 103.577953 154.601575 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_12\">\n",
       "    <path clip-path=\"url(#pea50b6e689)\" d=\"M 35.546457 109.247244 \n",
       "C 40.056998 109.247244 44.383406 107.455187 47.57284 104.265753 \n",
       "C 50.762274 101.076319 52.554331 96.749911 52.554331 92.23937 \n",
       "C 52.554331 87.728829 50.762274 83.402421 47.57284 80.212987 \n",
       "C 44.383406 77.023553 40.056998 75.231496 35.546457 75.231496 \n",
       "C 31.035916 75.231496 26.709508 77.023553 23.520074 80.212987 \n",
       "C 20.33064 83.402421 18.538583 87.728829 18.538583 92.23937 \n",
       "C 18.538583 96.749911 20.33064 101.076319 23.520074 104.265753 \n",
       "C 26.709508 107.455187 31.035916 109.247244 35.546457 109.247244 \n",
       "L 35.546457 109.247244 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_13\">\n",
       "    <path clip-path=\"url(#pea50b6e689)\" d=\"M 80.900787 52.554331 \n",
       "C 85.411328 52.554331 89.737736 50.762274 92.92717 47.57284 \n",
       "C 96.116605 44.383406 97.908661 40.056998 97.908661 35.546457 \n",
       "C 97.908661 31.035916 96.116605 26.709508 92.92717 23.520074 \n",
       "C 89.737736 20.33064 85.411328 18.538583 80.900787 18.538583 \n",
       "C 76.390246 18.538583 72.063838 20.33064 68.874404 23.520074 \n",
       "C 65.68497 26.709508 63.892913 31.035916 63.892913 35.546457 \n",
       "C 63.892913 40.056998 65.68497 44.383406 68.874404 47.57284 \n",
       "C 72.063838 50.762274 76.390246 52.554331 80.900787 52.554331 \n",
       "L 80.900787 52.554331 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_14\">\n",
       "    <path clip-path=\"url(#pea50b6e689)\" d=\"M 137.593701 109.247244 \n",
       "C 142.104242 109.247244 146.43065 107.455187 149.620084 104.265753 \n",
       "C 152.809518 101.076319 154.601575 96.749911 154.601575 92.23937 \n",
       "C 154.601575 87.728829 152.809518 83.402421 149.620084 80.212987 \n",
       "C 146.43065 77.023553 142.104242 75.231496 137.593701 75.231496 \n",
       "C 133.08316 75.231496 128.756752 77.023553 125.567318 80.212987 \n",
       "C 122.377884 83.402421 120.585827 87.728829 120.585827 92.23937 \n",
       "C 120.585827 96.749911 122.377884 101.076319 125.567318 104.265753 \n",
       "C 128.756752 107.455187 133.08316 109.247244 137.593701 109.247244 \n",
       "L 137.593701 109.247244 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_15\">\n",
       "    <path clip-path=\"url(#pea50b6e689)\" d=\"M 171.609449 52.554331 \n",
       "C 176.11999 52.554331 180.446398 50.762274 183.635832 47.57284 \n",
       "C 186.825266 44.383406 188.617323 40.056998 188.617323 35.546457 \n",
       "C 188.617323 31.035916 186.825266 26.709508 183.635832 23.520074 \n",
       "C 180.446398 20.33064 176.11999 18.538583 171.609449 18.538583 \n",
       "C 167.098908 18.538583 162.7725 20.33064 159.583066 23.520074 \n",
       "C 156.393632 26.709508 154.601575 31.035916 154.601575 35.546457 \n",
       "C 154.601575 40.056998 156.393632 44.383406 159.583066 47.57284 \n",
       "C 162.7725 50.762274 167.098908 52.554331 171.609449 52.554331 \n",
       "L 171.609449 52.554331 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_16\">\n",
       "    <path clip-path=\"url(#pea50b6e689)\" d=\"M 126.255118 109.247244 \n",
       "C 130.765659 109.247244 135.092067 107.455187 138.281501 104.265753 \n",
       "C 141.470935 101.076319 143.262992 96.749911 143.262992 92.23937 \n",
       "C 143.262992 87.728829 141.470935 83.402421 138.281501 80.212987 \n",
       "C 135.092067 77.023553 130.765659 75.231496 126.255118 75.231496 \n",
       "C 121.744577 75.231496 117.418169 77.023553 114.228735 80.212987 \n",
       "C 111.039301 83.402421 109.247244 87.728829 109.247244 92.23937 \n",
       "C 109.247244 96.749911 111.039301 101.076319 114.228735 104.265753 \n",
       "C 117.418169 107.455187 121.744577 109.247244 126.255118 109.247244 \n",
       "L 126.255118 109.247244 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_17\">\n",
       "    <path clip-path=\"url(#pea50b6e689)\" d=\"M 126.255118 52.554331 \n",
       "C 130.765659 52.554331 135.092067 50.762274 138.281501 47.57284 \n",
       "C 141.470935 44.383406 143.262992 40.056998 143.262992 35.546457 \n",
       "C 143.262992 31.035916 141.470935 26.709508 138.281501 23.520074 \n",
       "C 135.092067 20.33064 130.765659 18.538583 126.255118 18.538583 \n",
       "C 121.744577 18.538583 117.418169 20.33064 114.228735 23.520074 \n",
       "C 111.039301 26.709508 109.247244 31.035916 109.247244 35.546457 \n",
       "C 109.247244 40.056998 111.039301 44.383406 114.228735 47.57284 \n",
       "C 117.418169 50.762274 121.744577 52.554331 126.255118 52.554331 \n",
       "L 126.255118 52.554331 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"matplotlib.axis_1\"/>\n",
       "   <g id=\"matplotlib.axis_2\"/>\n",
       "   <g id=\"text_1\">\n",
       "    <!-- $z_n$ -->\n",
       "    <defs>\n",
       "     <path d=\"M 25.09375 45.90625 \n",
       "L 23.90625 40.203125 \n",
       "Q 28.40625 43.796875 32.203125 45.046875 \n",
       "Q 36 46.296875 40.5 46.296875 \n",
       "Q 45.203125 46.296875 48.09375 43.75 \n",
       "Q 51 41.203125 51 37.203125 \n",
       "Q 51 34.796875 50.40625 32.09375 \n",
       "L 42.40625 0 \n",
       "L 34.5 0 \n",
       "L 42 30.40625 \n",
       "Q 42.5 32.59375 42.5 33.90625 \n",
       "Q 42.5 39.203125 36 39.203125 \n",
       "Q 33.09375 39.203125 28.640625 36.703125 \n",
       "Q 24.203125 34.203125 21.703125 30.203125 \n",
       "L 14.203125 0 \n",
       "L 6.296875 0 \n",
       "L 17.203125 44 \n",
       "L 24.296875 46.40625 \n",
       "z\n",
       "\" id=\"STIXGeneral-Italic-1d62f\"/>\n",
       "     <path d=\"M 51.703125 45.296875 \n",
       "L 51.203125 43.296875 \n",
       "L 17 7.09375 \n",
       "L 43.40625 7.09375 \n",
       "L 40.703125 0 \n",
       "L 2.5 0 \n",
       "L 2.90625 2 \n",
       "L 37.09375 38.203125 \n",
       "L 14.40625 38.203125 \n",
       "L 17.296875 45.296875 \n",
       "z\n",
       "\" id=\"STIXGeneral-Italic-1d63b\"/>\n",
       "    </defs>\n",
       "    <g transform=\"translate(164.229448819 97.2062450787)scale(0.18 -0.18)\">\n",
       "     <use transform=\"translate(0.0 0.703125)\" xlink:href=\"#STIXGeneral-Italic-1d63b\"/>\n",
       "     <use transform=\"translate(44.69999694824219 -12.885937499999997)scale(0.7)\" xlink:href=\"#STIXGeneral-Italic-1d62f\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"text_2\">\n",
       "    <!-- $Y$ -->\n",
       "    <defs>\n",
       "     <path d=\"M 77.40625 66.203125 \n",
       "L 43 28.796875 \n",
       "L 35.796875 0 \n",
       "L 27.09375 0 \n",
       "L 34.203125 28.796875 \n",
       "L 18.59375 66.203125 \n",
       "L 28.09375 66.203125 \n",
       "L 40.5 36.203125 \n",
       "L 67.90625 66.203125 \n",
       "z\n",
       "\" id=\"STIXGeneral-Italic-1d620\"/>\n",
       "    </defs>\n",
       "    <g transform=\"translate(97.9079527559 142.560575787)scale(0.18 -0.18)\">\n",
       "     <use transform=\"translate(0.0 0.796875)\" xlink:href=\"#STIXGeneral-Italic-1d620\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"text_3\">\n",
       "    <!-- $z_0$ -->\n",
       "    <defs>\n",
       "     <path d=\"M 47.703125 33 \n",
       "Q 47.703125 23.796875 45.546875 16.34375 \n",
       "Q 43.40625 8.90625 38.09375 3.75 \n",
       "Q 32.796875 -1.40625 25 -1.40625 \n",
       "Q 18.796875 -1.40625 14.25 1.6875 \n",
       "Q 9.703125 4.796875 7.203125 10.046875 \n",
       "Q 4.703125 15.296875 3.5 21.140625 \n",
       "Q 2.296875 27 2.296875 33.59375 \n",
       "Q 2.296875 42.90625 4.59375 50.34375 \n",
       "Q 6.90625 57.796875 12.296875 62.6875 \n",
       "Q 17.703125 67.59375 25.40625 67.59375 \n",
       "Q 35.203125 67.59375 41.453125 57.9375 \n",
       "Q 47.703125 48.296875 47.703125 33 \n",
       "M 39.796875 33 \n",
       "Q 39.796875 45.203125 35.75 52.84375 \n",
       "Q 31.703125 60.5 25.203125 60.5 \n",
       "Q 17.796875 60.5 14 52.75 \n",
       "Q 10.203125 45 10.203125 33.40625 \n",
       "Q 10.203125 28.203125 10.953125 23.546875 \n",
       "Q 11.703125 18.90625 13.34375 14.75 \n",
       "Q 15 10.59375 18 8.140625 \n",
       "Q 21 5.703125 25 5.703125 \n",
       "Q 30.09375 5.703125 33.546875 9.796875 \n",
       "Q 37 13.90625 38.390625 19.84375 \n",
       "Q 39.796875 25.796875 39.796875 33 \n",
       "\" id=\"STIXGeneral-Regular-1d7e2\"/>\n",
       "    </defs>\n",
       "    <g transform=\"translate(28.1664566929 97.2062450787)scale(0.18 -0.18)\">\n",
       "     <use transform=\"translate(0.0 0.703125)\" xlink:href=\"#STIXGeneral-Italic-1d63b\"/>\n",
       "     <use transform=\"translate(44.69999694824219 -12.885937499999997)scale(0.7)\" xlink:href=\"#STIXGeneral-Regular-1d7e2\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"text_4\">\n",
       "    <!-- $x_1$ -->\n",
       "    <defs>\n",
       "     <path d=\"M 54.40625 45.296875 \n",
       "L 34.40625 23.59375 \n",
       "L 45.203125 0 \n",
       "L 35.796875 0 \n",
       "L 27.90625 17.5 \n",
       "L 12.40625 0 \n",
       "L 3 0 \n",
       "L 25 23.90625 \n",
       "L 15.40625 45.296875 \n",
       "L 24.796875 45.296875 \n",
       "L 31.59375 30.203125 \n",
       "L 45 45.296875 \n",
       "z\n",
       "\" id=\"STIXGeneral-Italic-1d639\"/>\n",
       "     <path d=\"M 30.203125 0 \n",
       "L 22.296875 0 \n",
       "L 22.296875 57 \n",
       "Q 20.09375 56 15.75 53.75 \n",
       "Q 11.40625 51.5 10.796875 51.203125 \n",
       "L 10.796875 58.5 \n",
       "L 28.796875 67.703125 \n",
       "L 30.203125 67.203125 \n",
       "z\n",
       "\" id=\"STIXGeneral-Regular-1d7e3\"/>\n",
       "    </defs>\n",
       "    <g transform=\"translate(73.1607874016 40.5133316929)scale(0.18 -0.18)\">\n",
       "     <use transform=\"translate(0.0 0.703125)\" xlink:href=\"#STIXGeneral-Italic-1d639\"/>\n",
       "     <use transform=\"translate(48.19999694824219 -12.885937499999997)scale(0.7)\" xlink:href=\"#STIXGeneral-Regular-1d7e3\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"text_5\">\n",
       "    <!-- $z_1$ -->\n",
       "    <g transform=\"translate(130.213700787 97.2062450787)scale(0.18 -0.18)\">\n",
       "     <use transform=\"translate(0.0 0.703125)\" xlink:href=\"#STIXGeneral-Italic-1d63b\"/>\n",
       "     <use transform=\"translate(44.69999694824219 -12.885937499999997)scale(0.7)\" xlink:href=\"#STIXGeneral-Regular-1d7e3\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"text_6\">\n",
       "    <!-- $x_n$ -->\n",
       "    <g transform=\"translate(163.959448819 40.5133316929)scale(0.18 -0.18)\">\n",
       "     <use transform=\"translate(0.0 0.703125)\" xlink:href=\"#STIXGeneral-Italic-1d639\"/>\n",
       "     <use transform=\"translate(48.19999694824219 -12.885937499999997)scale(0.7)\" xlink:href=\"#STIXGeneral-Italic-1d62f\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"text_7\">\n",
       "    <!-- $\\dots$ -->\n",
       "    <defs>\n",
       "     <path d=\"M 88.796875 4.296875 \n",
       "Q 88.796875 2.09375 87.140625 0.5 \n",
       "Q 85.5 -1.09375 83.203125 -1.09375 \n",
       "Q 80.90625 -1.09375 79.296875 0.5 \n",
       "Q 77.703125 2.09375 77.703125 4.390625 \n",
       "Q 77.703125 6.703125 79.34375 8.34375 \n",
       "Q 81 10 83.296875 10 \n",
       "Q 85.5 10 87.140625 8.296875 \n",
       "Q 88.796875 6.59375 88.796875 4.296875 \n",
       "M 55.5 4.296875 \n",
       "Q 55.5 2.09375 53.84375 0.5 \n",
       "Q 52.203125 -1.09375 49.890625 -1.09375 \n",
       "Q 47.59375 -1.09375 46 0.5 \n",
       "Q 44.40625 2.09375 44.40625 4.390625 \n",
       "Q 44.40625 6.703125 46.046875 8.34375 \n",
       "Q 47.703125 10 50 10 \n",
       "Q 52.203125 10 53.84375 8.296875 \n",
       "Q 55.5 6.59375 55.5 4.296875 \n",
       "M 22.203125 4.296875 \n",
       "Q 22.203125 2.09375 20.546875 0.5 \n",
       "Q 18.90625 -1.09375 16.59375 -1.09375 \n",
       "Q 14.296875 -1.09375 12.6875 0.5 \n",
       "Q 11.09375 2.09375 11.09375 4.390625 \n",
       "Q 11.09375 6.703125 12.75 8.34375 \n",
       "Q 14.40625 10 16.703125 10 \n",
       "Q 18.90625 10 20.546875 8.296875 \n",
       "Q 22.203125 6.59375 22.203125 4.296875 \n",
       "\" id=\"STIXGeneral-Regular-2026\"/>\n",
       "    </defs>\n",
       "    <g transform=\"translate(117.25511811 97.2062450787)scale(0.18 -0.18)\">\n",
       "     <use xlink:href=\"#STIXGeneral-Regular-2026\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"text_8\">\n",
       "    <!-- $\\dots$ -->\n",
       "    <g transform=\"translate(117.25511811 40.5133316929)scale(0.18 -0.18)\">\n",
       "     <use xlink:href=\"#STIXGeneral-Regular-2026\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "  </g>\n",
       " </g>\n",
       " <defs>\n",
       "  <clipPath id=\"pea50b6e689\">\n",
       "   <rect height=\"170.078740157\" width=\"226.771653543\" x=\"7.2\" y=\"7.2\"/>\n",
       "  </clipPath>\n",
       " </defs>\n",
       "</svg>\n"
      ],
      "text/plain": [
       "<matplotlib.figure.Figure at 0x7feb96bfbb38>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "pgm = daft.PGM([4, 3], origin=[-0.5, 0.5], observed_style='inner')\n",
    "add_node(pgm, 'z0', '$z_0$', 0, 2)\n",
    "add_node(pgm, 'z1', '$z_1$', 1.8, 2)\n",
    "add_node(pgm, 'z', r'$\\dots$', 1.6, 2)\n",
    "add_node(pgm, 'zn', '$z_n$', 2.4, 2)\n",
    "add_node(pgm, 'x1', '$x_1$', 0.8, 3)\n",
    "add_node(pgm, 'x', r'$\\dots$', 1.6, 3)\n",
    "add_node(pgm, 'xn', '$x_n$', 2.4, 3)\n",
    "add_node(pgm, 'Y', '$Y$', 1.2, 1.2, observed=True)\n",
    "add_edges(pgm, [\n",
    "        ('z1', 'Y'),\n",
    "        ('z', 'Y'),\n",
    "        ('zn', 'Y'),\n",
    "        ('z0', 'Y'),\n",
    "        ('x1', 'z1'),\n",
    "        ('x', 'z'),\n",
    "        ('xn', 'zn')\n",
    "    ])\n",
    "pgm.render()\n",
    "save('bn_noisy_or_cpd')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 47,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "image/svg+xml": [
       "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"no\"?>\n",
       "<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\n",
       "  \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n",
       "<!-- Created with matplotlib (http://matplotlib.org/) -->\n",
       "<svg height=\"71pt\" version=\"1.1\" viewBox=\"0 0 127 71\" width=\"127pt\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n",
       " <defs>\n",
       "  <style type=\"text/css\">\n",
       "*{stroke-linecap:butt;stroke-linejoin:round;stroke-miterlimit:100000;}\n",
       "  </style>\n",
       " </defs>\n",
       " <g id=\"figure_1\">\n",
       "  <g id=\"patch_1\">\n",
       "   <path d=\"M 0 71.092913 \n",
       "L 127.785827 71.092913 \n",
       "L 127.785827 0 \n",
       "L 0 0 \n",
       "L 0 71.092913 \n",
       "z\n",
       "\" style=\"fill:none;\"/>\n",
       "  </g>\n",
       "  <g id=\"axes_1\">\n",
       "   <g id=\"patch_2\">\n",
       "    <path clip-path=\"url(#pcfd3c40894)\" d=\"M 75.231496 35.546457 \n",
       "L 72.39685 37.672441 \n",
       "L 72.39685 35.546457 \n",
       "L 52.554331 35.546457 \n",
       "L 52.554331 35.546457 \n",
       "L 72.39685 35.546457 \n",
       "L 72.39685 33.420472 \n",
       "L 75.231496 35.546457 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_3\">\n",
       "    <path clip-path=\"url(#pcfd3c40894)\" d=\"M 35.546457 52.554331 \n",
       "C 40.056998 52.554331 44.383406 50.762274 47.57284 47.57284 \n",
       "C 50.762274 44.383406 52.554331 40.056998 52.554331 35.546457 \n",
       "C 52.554331 31.035916 50.762274 26.709508 47.57284 23.520074 \n",
       "C 44.383406 20.33064 40.056998 18.538583 35.546457 18.538583 \n",
       "C 31.035916 18.538583 26.709508 20.33064 23.520074 23.520074 \n",
       "C 20.33064 26.709508 18.538583 31.035916 18.538583 35.546457 \n",
       "C 18.538583 40.056998 20.33064 44.383406 23.520074 47.57284 \n",
       "C 26.709508 50.762274 31.035916 52.554331 35.546457 52.554331 \n",
       "L 35.546457 52.554331 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_4\">\n",
       "    <path clip-path=\"url(#pcfd3c40894)\" d=\"M 92.23937 52.554331 \n",
       "C 96.749911 52.554331 101.076319 50.762274 104.265753 47.57284 \n",
       "C 107.455187 44.383406 109.247244 40.056998 109.247244 35.546457 \n",
       "C 109.247244 31.035916 107.455187 26.709508 104.265753 23.520074 \n",
       "C 101.076319 20.33064 96.749911 18.538583 92.23937 18.538583 \n",
       "C 87.728829 18.538583 83.402421 20.33064 80.212987 23.520074 \n",
       "C 77.023553 26.709508 75.231496 31.035916 75.231496 35.546457 \n",
       "C 75.231496 40.056998 77.023553 44.383406 80.212987 47.57284 \n",
       "C 83.402421 50.762274 87.728829 52.554331 92.23937 52.554331 \n",
       "L 92.23937 52.554331 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"matplotlib.axis_1\"/>\n",
       "   <g id=\"matplotlib.axis_2\"/>\n",
       "   <g id=\"text_1\">\n",
       "    <!-- T -->\n",
       "    <defs>\n",
       "     <path d=\"M -0.296875 72.90625 \n",
       "L 61.375 72.90625 \n",
       "L 61.375 64.59375 \n",
       "L 35.5 64.59375 \n",
       "L 35.5 0 \n",
       "L 25.59375 0 \n",
       "L 25.59375 64.59375 \n",
       "L -0.296875 64.59375 \n",
       "z\n",
       "\" id=\"BitstreamVeraSans-Roman-54\"/>\n",
       "    </defs>\n",
       "    <g transform=\"translate(30.0494254429 40.5133316929)scale(0.18 -0.18)\">\n",
       "     <use xlink:href=\"#BitstreamVeraSans-Roman-54\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"text_2\">\n",
       "    <!-- S -->\n",
       "    <defs>\n",
       "     <path d=\"M 53.515625 70.515625 \n",
       "L 53.515625 60.890625 \n",
       "Q 47.90625 63.578125 42.921875 64.890625 \n",
       "Q 37.9375 66.21875 33.296875 66.21875 \n",
       "Q 25.25 66.21875 20.875 63.09375 \n",
       "Q 16.5 59.96875 16.5 54.203125 \n",
       "Q 16.5 49.359375 19.40625 46.890625 \n",
       "Q 22.3125 44.4375 30.421875 42.921875 \n",
       "L 36.375 41.703125 \n",
       "Q 47.40625 39.59375 52.65625 34.296875 \n",
       "Q 57.90625 29 57.90625 20.125 \n",
       "Q 57.90625 9.515625 50.796875 4.046875 \n",
       "Q 43.703125 -1.421875 29.984375 -1.421875 \n",
       "Q 24.8125 -1.421875 18.96875 -0.25 \n",
       "Q 13.140625 0.921875 6.890625 3.21875 \n",
       "L 6.890625 13.375 \n",
       "Q 12.890625 10.015625 18.65625 8.296875 \n",
       "Q 24.421875 6.59375 29.984375 6.59375 \n",
       "Q 38.421875 6.59375 43.015625 9.90625 \n",
       "Q 47.609375 13.234375 47.609375 19.390625 \n",
       "Q 47.609375 24.75 44.3125 27.78125 \n",
       "Q 41.015625 30.8125 33.5 32.328125 \n",
       "L 27.484375 33.5 \n",
       "Q 16.453125 35.6875 11.515625 40.375 \n",
       "Q 6.59375 45.0625 6.59375 53.421875 \n",
       "Q 6.59375 63.09375 13.40625 68.65625 \n",
       "Q 20.21875 74.21875 32.171875 74.21875 \n",
       "Q 37.3125 74.21875 42.625 73.28125 \n",
       "Q 47.953125 72.359375 53.515625 70.515625 \n",
       "\" id=\"BitstreamVeraSans-Roman-53\"/>\n",
       "    </defs>\n",
       "    <g transform=\"translate(86.5257763287 40.5133316929)scale(0.18 -0.18)\">\n",
       "     <use xlink:href=\"#BitstreamVeraSans-Roman-53\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "  </g>\n",
       " </g>\n",
       " <defs>\n",
       "  <clipPath id=\"pcfd3c40894\">\n",
       "   <rect height=\"56.6929133858\" width=\"113.385826772\" x=\"7.2\" y=\"7.2\"/>\n",
       "  </clipPath>\n",
       " </defs>\n",
       "</svg>\n"
      ],
      "text/plain": [
       "<matplotlib.figure.Figure at 0x7feb9696b2e8>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "pgm = daft.PGM([2, 1], origin=[-0.5, 0.5])\n",
    "add_node(pgm, 't', 'T', 0, 1)\n",
    "add_node(pgm, 's', 'S', 1, 1)\n",
    "add_edges(pgm, [\n",
    "        ('t', 's'),\n",
    "    ])\n",
    "pgm.render()\n",
    "save('bn_continuous_ex_00')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 48,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "image/svg+xml": [
       "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"no\"?>\n",
       "<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\n",
       "  \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n",
       "<!-- Created with matplotlib (http://matplotlib.org/) -->\n",
       "<svg height=\"127pt\" version=\"1.1\" viewBox=\"0 0 127 127\" width=\"127pt\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n",
       " <defs>\n",
       "  <style type=\"text/css\">\n",
       "*{stroke-linecap:butt;stroke-linejoin:round;stroke-miterlimit:100000;}\n",
       "  </style>\n",
       " </defs>\n",
       " <g id=\"figure_1\">\n",
       "  <g id=\"patch_1\">\n",
       "   <path d=\"M 0 127.785827 \n",
       "L 127.785827 127.785827 \n",
       "L 127.785827 0 \n",
       "L 0 0 \n",
       "L 0 127.785827 \n",
       "z\n",
       "\" style=\"fill:none;\"/>\n",
       "  </g>\n",
       "  <g id=\"axes_1\">\n",
       "   <g id=\"patch_2\">\n",
       "    <path clip-path=\"url(#p96d0bbbbe1)\" d=\"M 75.231496 35.546457 \n",
       "L 72.39685 37.672441 \n",
       "L 72.39685 35.546457 \n",
       "L 52.554331 35.546457 \n",
       "L 52.554331 35.546457 \n",
       "L 72.39685 35.546457 \n",
       "L 72.39685 33.420472 \n",
       "L 75.231496 35.546457 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_3\">\n",
       "    <path clip-path=\"url(#p96d0bbbbe1)\" d=\"M 80.212987 80.212987 \n",
       "L 76.705292 79.711888 \n",
       "L 78.20859 78.20859 \n",
       "L 47.57284 47.57284 \n",
       "L 47.57284 47.57284 \n",
       "L 78.20859 78.20859 \n",
       "L 79.711888 76.705292 \n",
       "L 80.212987 80.212987 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_4\">\n",
       "    <path clip-path=\"url(#p96d0bbbbe1)\" d=\"M 75.231496 92.23937 \n",
       "L 72.39685 94.365354 \n",
       "L 72.39685 92.23937 \n",
       "L 52.554331 92.23937 \n",
       "L 52.554331 92.23937 \n",
       "L 72.39685 92.23937 \n",
       "L 72.39685 90.113386 \n",
       "L 75.231496 92.23937 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_5\">\n",
       "    <path clip-path=\"url(#p96d0bbbbe1)\" d=\"M 92.23937 109.247244 \n",
       "C 96.749911 109.247244 101.076319 107.455187 104.265753 104.265753 \n",
       "C 107.455187 101.076319 109.247244 96.749911 109.247244 92.23937 \n",
       "C 109.247244 87.728829 107.455187 83.402421 104.265753 80.212987 \n",
       "C 101.076319 77.023553 96.749911 75.231496 92.23937 75.231496 \n",
       "C 87.728829 75.231496 83.402421 77.023553 80.212987 80.212987 \n",
       "C 77.023553 83.402421 75.231496 87.728829 75.231496 92.23937 \n",
       "C 75.231496 96.749911 77.023553 101.076319 80.212987 104.265753 \n",
       "C 83.402421 107.455187 87.728829 109.247244 92.23937 109.247244 \n",
       "L 92.23937 109.247244 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_6\">\n",
       "    <path clip-path=\"url(#p96d0bbbbe1)\" d=\"M 35.546457 52.554331 \n",
       "C 40.056998 52.554331 44.383406 50.762274 47.57284 47.57284 \n",
       "C 50.762274 44.383406 52.554331 40.056998 52.554331 35.546457 \n",
       "C 52.554331 31.035916 50.762274 26.709508 47.57284 23.520074 \n",
       "C 44.383406 20.33064 40.056998 18.538583 35.546457 18.538583 \n",
       "C 31.035916 18.538583 26.709508 20.33064 23.520074 23.520074 \n",
       "C 20.33064 26.709508 18.538583 31.035916 18.538583 35.546457 \n",
       "C 18.538583 40.056998 20.33064 44.383406 23.520074 47.57284 \n",
       "C 26.709508 50.762274 31.035916 52.554331 35.546457 52.554331 \n",
       "L 35.546457 52.554331 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_7\">\n",
       "    <path clip-path=\"url(#p96d0bbbbe1)\" d=\"M 35.546457 109.247244 \n",
       "C 40.056998 109.247244 44.383406 107.455187 47.57284 104.265753 \n",
       "C 50.762274 101.076319 52.554331 96.749911 52.554331 92.23937 \n",
       "C 52.554331 87.728829 50.762274 83.402421 47.57284 80.212987 \n",
       "C 44.383406 77.023553 40.056998 75.231496 35.546457 75.231496 \n",
       "C 31.035916 75.231496 26.709508 77.023553 23.520074 80.212987 \n",
       "C 20.33064 83.402421 18.538583 87.728829 18.538583 92.23937 \n",
       "C 18.538583 96.749911 20.33064 101.076319 23.520074 104.265753 \n",
       "C 26.709508 107.455187 31.035916 109.247244 35.546457 109.247244 \n",
       "L 35.546457 109.247244 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_8\">\n",
       "    <path clip-path=\"url(#p96d0bbbbe1)\" d=\"M 92.23937 52.554331 \n",
       "C 96.749911 52.554331 101.076319 50.762274 104.265753 47.57284 \n",
       "C 107.455187 44.383406 109.247244 40.056998 109.247244 35.546457 \n",
       "C 109.247244 31.035916 107.455187 26.709508 104.265753 23.520074 \n",
       "C 101.076319 20.33064 96.749911 18.538583 92.23937 18.538583 \n",
       "C 87.728829 18.538583 83.402421 20.33064 80.212987 23.520074 \n",
       "C 77.023553 26.709508 75.231496 31.035916 75.231496 35.546457 \n",
       "C 75.231496 40.056998 77.023553 44.383406 80.212987 47.57284 \n",
       "C 83.402421 50.762274 87.728829 52.554331 92.23937 52.554331 \n",
       "L 92.23937 52.554331 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"matplotlib.axis_1\"/>\n",
       "   <g id=\"matplotlib.axis_2\"/>\n",
       "   <g id=\"text_1\">\n",
       "    <!-- T' -->\n",
       "    <defs>\n",
       "     <path d=\"M 17.921875 72.90625 \n",
       "L 17.921875 45.796875 \n",
       "L 9.625 45.796875 \n",
       "L 9.625 72.90625 \n",
       "z\n",
       "\" id=\"BitstreamVeraSans-Roman-27\"/>\n",
       "     <path d=\"M -0.296875 72.90625 \n",
       "L 61.375 72.90625 \n",
       "L 61.375 64.59375 \n",
       "L 35.5 64.59375 \n",
       "L 35.5 0 \n",
       "L 25.59375 0 \n",
       "L 25.59375 64.59375 \n",
       "L -0.296875 64.59375 \n",
       "z\n",
       "\" id=\"BitstreamVeraSans-Roman-54\"/>\n",
       "    </defs>\n",
       "    <g transform=\"translate(84.2687450787 97.2062450787)scale(0.18 -0.18)\">\n",
       "     <use xlink:href=\"#BitstreamVeraSans-Roman-54\"/>\n",
       "     <use x=\"61.083984375\" xlink:href=\"#BitstreamVeraSans-Roman-27\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"text_2\">\n",
       "    <!-- T -->\n",
       "    <g transform=\"translate(30.0494254429 40.5133316929)scale(0.18 -0.18)\">\n",
       "     <use xlink:href=\"#BitstreamVeraSans-Roman-54\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"text_3\">\n",
       "    <!-- O -->\n",
       "    <defs>\n",
       "     <path d=\"M 39.40625 66.21875 \n",
       "Q 28.65625 66.21875 22.328125 58.203125 \n",
       "Q 16.015625 50.203125 16.015625 36.375 \n",
       "Q 16.015625 22.609375 22.328125 14.59375 \n",
       "Q 28.65625 6.59375 39.40625 6.59375 \n",
       "Q 50.140625 6.59375 56.421875 14.59375 \n",
       "Q 62.703125 22.609375 62.703125 36.375 \n",
       "Q 62.703125 50.203125 56.421875 58.203125 \n",
       "Q 50.140625 66.21875 39.40625 66.21875 \n",
       "M 39.40625 74.21875 \n",
       "Q 54.734375 74.21875 63.90625 63.9375 \n",
       "Q 73.09375 53.65625 73.09375 36.375 \n",
       "Q 73.09375 19.140625 63.90625 8.859375 \n",
       "Q 54.734375 -1.421875 39.40625 -1.421875 \n",
       "Q 24.03125 -1.421875 14.8125 8.828125 \n",
       "Q 5.609375 19.09375 5.609375 36.375 \n",
       "Q 5.609375 53.65625 14.8125 63.9375 \n",
       "Q 24.03125 74.21875 39.40625 74.21875 \n",
       "\" id=\"BitstreamVeraSans-Roman-4f\"/>\n",
       "    </defs>\n",
       "    <g transform=\"translate(28.4617691929 97.2062450787)scale(0.18 -0.18)\">\n",
       "     <use xlink:href=\"#BitstreamVeraSans-Roman-4f\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"text_4\">\n",
       "    <!-- S -->\n",
       "    <defs>\n",
       "     <path d=\"M 53.515625 70.515625 \n",
       "L 53.515625 60.890625 \n",
       "Q 47.90625 63.578125 42.921875 64.890625 \n",
       "Q 37.9375 66.21875 33.296875 66.21875 \n",
       "Q 25.25 66.21875 20.875 63.09375 \n",
       "Q 16.5 59.96875 16.5 54.203125 \n",
       "Q 16.5 49.359375 19.40625 46.890625 \n",
       "Q 22.3125 44.4375 30.421875 42.921875 \n",
       "L 36.375 41.703125 \n",
       "Q 47.40625 39.59375 52.65625 34.296875 \n",
       "Q 57.90625 29 57.90625 20.125 \n",
       "Q 57.90625 9.515625 50.796875 4.046875 \n",
       "Q 43.703125 -1.421875 29.984375 -1.421875 \n",
       "Q 24.8125 -1.421875 18.96875 -0.25 \n",
       "Q 13.140625 0.921875 6.890625 3.21875 \n",
       "L 6.890625 13.375 \n",
       "Q 12.890625 10.015625 18.65625 8.296875 \n",
       "Q 24.421875 6.59375 29.984375 6.59375 \n",
       "Q 38.421875 6.59375 43.015625 9.90625 \n",
       "Q 47.609375 13.234375 47.609375 19.390625 \n",
       "Q 47.609375 24.75 44.3125 27.78125 \n",
       "Q 41.015625 30.8125 33.5 32.328125 \n",
       "L 27.484375 33.5 \n",
       "Q 16.453125 35.6875 11.515625 40.375 \n",
       "Q 6.59375 45.0625 6.59375 53.421875 \n",
       "Q 6.59375 63.09375 13.40625 68.65625 \n",
       "Q 20.21875 74.21875 32.171875 74.21875 \n",
       "Q 37.3125 74.21875 42.625 73.28125 \n",
       "Q 47.953125 72.359375 53.515625 70.515625 \n",
       "\" id=\"BitstreamVeraSans-Roman-53\"/>\n",
       "    </defs>\n",
       "    <g transform=\"translate(86.5257763287 40.5133316929)scale(0.18 -0.18)\">\n",
       "     <use xlink:href=\"#BitstreamVeraSans-Roman-53\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "  </g>\n",
       " </g>\n",
       " <defs>\n",
       "  <clipPath id=\"p96d0bbbbe1\">\n",
       "   <rect height=\"113.385826772\" width=\"113.385826772\" x=\"7.2\" y=\"7.2\"/>\n",
       "  </clipPath>\n",
       " </defs>\n",
       "</svg>\n"
      ],
      "text/plain": [
       "<matplotlib.figure.Figure at 0x7feb9696b080>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "pgm = daft.PGM([2, 2], origin=[-0.5, 0.5])\n",
    "add_node(pgm, 't', 'T', 0, 2)\n",
    "add_node(pgm, 's', 'S', 1, 2)\n",
    "add_node(pgm, 't_', 'T\\'', 1, 1)\n",
    "add_node(pgm, 'o', 'O', 0, 1)\n",
    "add_edges(pgm, [\n",
    "        ('t', 's'),\n",
    "        ('t', 't_'),\n",
    "        ('o', 't_')\n",
    "    ])\n",
    "pgm.render()\n",
    "save('bn_continuous_ex_01')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 49,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "image/svg+xml": [
       "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"no\"?>\n",
       "<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\n",
       "  \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n",
       "<!-- Created with matplotlib (http://matplotlib.org/) -->\n",
       "<svg height=\"184pt\" version=\"1.1\" viewBox=\"0 0 127 184\" width=\"127pt\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n",
       " <defs>\n",
       "  <style type=\"text/css\">\n",
       "*{stroke-linecap:butt;stroke-linejoin:round;stroke-miterlimit:100000;}\n",
       "  </style>\n",
       " </defs>\n",
       " <g id=\"figure_1\">\n",
       "  <g id=\"patch_1\">\n",
       "   <path d=\"M 0 184.47874 \n",
       "L 127.785827 184.47874 \n",
       "L 127.785827 0 \n",
       "L 0 0 \n",
       "L 0 184.47874 \n",
       "z\n",
       "\" style=\"fill:none;\"/>\n",
       "  </g>\n",
       "  <g id=\"axes_1\">\n",
       "   <g id=\"patch_2\">\n",
       "    <path clip-path=\"url(#pbd259e8e36)\" d=\"M 75.231496 35.546457 \n",
       "L 72.39685 37.672441 \n",
       "L 72.39685 35.546457 \n",
       "L 52.554331 35.546457 \n",
       "L 52.554331 35.546457 \n",
       "L 72.39685 35.546457 \n",
       "L 72.39685 33.420472 \n",
       "L 75.231496 35.546457 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_3\">\n",
       "    <path clip-path=\"url(#pbd259e8e36)\" d=\"M 80.212987 80.212987 \n",
       "L 76.705292 79.711888 \n",
       "L 78.20859 78.20859 \n",
       "L 47.57284 47.57284 \n",
       "L 47.57284 47.57284 \n",
       "L 78.20859 78.20859 \n",
       "L 79.711888 76.705292 \n",
       "L 80.212987 80.212987 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_4\">\n",
       "    <path clip-path=\"url(#pbd259e8e36)\" d=\"M 75.231496 92.23937 \n",
       "L 72.39685 94.365354 \n",
       "L 72.39685 92.23937 \n",
       "L 52.554331 92.23937 \n",
       "L 52.554331 92.23937 \n",
       "L 72.39685 92.23937 \n",
       "L 72.39685 90.113386 \n",
       "L 75.231496 92.23937 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_5\">\n",
       "    <path clip-path=\"url(#pbd259e8e36)\" d=\"M 80.212987 104.265753 \n",
       "L 79.711888 107.773448 \n",
       "L 78.20859 106.27015 \n",
       "L 47.57284 136.9059 \n",
       "L 47.57284 136.9059 \n",
       "L 78.20859 106.27015 \n",
       "L 76.705292 104.766852 \n",
       "L 80.212987 104.265753 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_6\">\n",
       "    <path clip-path=\"url(#pbd259e8e36)\" d=\"M 92.23937 109.247244 \n",
       "C 96.749911 109.247244 101.076319 107.455187 104.265753 104.265753 \n",
       "C 107.455187 101.076319 109.247244 96.749911 109.247244 92.23937 \n",
       "C 109.247244 87.728829 107.455187 83.402421 104.265753 80.212987 \n",
       "C 101.076319 77.023553 96.749911 75.231496 92.23937 75.231496 \n",
       "C 87.728829 75.231496 83.402421 77.023553 80.212987 80.212987 \n",
       "C 77.023553 83.402421 75.231496 87.728829 75.231496 92.23937 \n",
       "C 75.231496 96.749911 77.023553 101.076319 80.212987 104.265753 \n",
       "C 83.402421 107.455187 87.728829 109.247244 92.23937 109.247244 \n",
       "L 92.23937 109.247244 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_7\">\n",
       "    <path clip-path=\"url(#pbd259e8e36)\" d=\"M 35.546457 52.554331 \n",
       "C 40.056998 52.554331 44.383406 50.762274 47.57284 47.57284 \n",
       "C 50.762274 44.383406 52.554331 40.056998 52.554331 35.546457 \n",
       "C 52.554331 31.035916 50.762274 26.709508 47.57284 23.520074 \n",
       "C 44.383406 20.33064 40.056998 18.538583 35.546457 18.538583 \n",
       "C 31.035916 18.538583 26.709508 20.33064 23.520074 23.520074 \n",
       "C 20.33064 26.709508 18.538583 31.035916 18.538583 35.546457 \n",
       "C 18.538583 40.056998 20.33064 44.383406 23.520074 47.57284 \n",
       "C 26.709508 50.762274 31.035916 52.554331 35.546457 52.554331 \n",
       "L 35.546457 52.554331 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_8\">\n",
       "    <path clip-path=\"url(#pbd259e8e36)\" d=\"M 35.546457 109.247244 \n",
       "C 40.056998 109.247244 44.383406 107.455187 47.57284 104.265753 \n",
       "C 50.762274 101.076319 52.554331 96.749911 52.554331 92.23937 \n",
       "C 52.554331 87.728829 50.762274 83.402421 47.57284 80.212987 \n",
       "C 44.383406 77.023553 40.056998 75.231496 35.546457 75.231496 \n",
       "C 31.035916 75.231496 26.709508 77.023553 23.520074 80.212987 \n",
       "C 20.33064 83.402421 18.538583 87.728829 18.538583 92.23937 \n",
       "C 18.538583 96.749911 20.33064 101.076319 23.520074 104.265753 \n",
       "C 26.709508 107.455187 31.035916 109.247244 35.546457 109.247244 \n",
       "L 35.546457 109.247244 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_9\">\n",
       "    <path clip-path=\"url(#pbd259e8e36)\" d=\"M 35.546457 165.940157 \n",
       "C 40.056998 165.940157 44.383406 164.148101 47.57284 160.958667 \n",
       "C 50.762274 157.769232 52.554331 153.442824 52.554331 148.932283 \n",
       "C 52.554331 144.421743 50.762274 140.095334 47.57284 136.9059 \n",
       "C 44.383406 133.716466 40.056998 131.924409 35.546457 131.924409 \n",
       "C 31.035916 131.924409 26.709508 133.716466 23.520074 136.9059 \n",
       "C 20.33064 140.095334 18.538583 144.421743 18.538583 148.932283 \n",
       "C 18.538583 153.442824 20.33064 157.769232 23.520074 160.958667 \n",
       "C 26.709508 164.148101 31.035916 165.940157 35.546457 165.940157 \n",
       "L 35.546457 165.940157 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_10\">\n",
       "    <path clip-path=\"url(#pbd259e8e36)\" d=\"M 92.23937 52.554331 \n",
       "C 96.749911 52.554331 101.076319 50.762274 104.265753 47.57284 \n",
       "C 107.455187 44.383406 109.247244 40.056998 109.247244 35.546457 \n",
       "C 109.247244 31.035916 107.455187 26.709508 104.265753 23.520074 \n",
       "C 101.076319 20.33064 96.749911 18.538583 92.23937 18.538583 \n",
       "C 87.728829 18.538583 83.402421 20.33064 80.212987 23.520074 \n",
       "C 77.023553 26.709508 75.231496 31.035916 75.231496 35.546457 \n",
       "C 75.231496 40.056998 77.023553 44.383406 80.212987 47.57284 \n",
       "C 83.402421 50.762274 87.728829 52.554331 92.23937 52.554331 \n",
       "L 92.23937 52.554331 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"matplotlib.axis_1\"/>\n",
       "   <g id=\"matplotlib.axis_2\"/>\n",
       "   <g id=\"text_1\">\n",
       "    <!-- T' -->\n",
       "    <defs>\n",
       "     <path d=\"M 17.921875 72.90625 \n",
       "L 17.921875 45.796875 \n",
       "L 9.625 45.796875 \n",
       "L 9.625 72.90625 \n",
       "z\n",
       "\" id=\"BitstreamVeraSans-Roman-27\"/>\n",
       "     <path d=\"M -0.296875 72.90625 \n",
       "L 61.375 72.90625 \n",
       "L 61.375 64.59375 \n",
       "L 35.5 64.59375 \n",
       "L 35.5 0 \n",
       "L 25.59375 0 \n",
       "L 25.59375 64.59375 \n",
       "L -0.296875 64.59375 \n",
       "z\n",
       "\" id=\"BitstreamVeraSans-Roman-54\"/>\n",
       "    </defs>\n",
       "    <g transform=\"translate(84.2687450787 97.2062450787)scale(0.18 -0.18)\">\n",
       "     <use xlink:href=\"#BitstreamVeraSans-Roman-54\"/>\n",
       "     <use x=\"61.083984375\" xlink:href=\"#BitstreamVeraSans-Roman-27\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"text_2\">\n",
       "    <!-- T -->\n",
       "    <g transform=\"translate(30.0494254429 40.5133316929)scale(0.18 -0.18)\">\n",
       "     <use xlink:href=\"#BitstreamVeraSans-Roman-54\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"text_3\">\n",
       "    <!-- O -->\n",
       "    <defs>\n",
       "     <path d=\"M 39.40625 66.21875 \n",
       "Q 28.65625 66.21875 22.328125 58.203125 \n",
       "Q 16.015625 50.203125 16.015625 36.375 \n",
       "Q 16.015625 22.609375 22.328125 14.59375 \n",
       "Q 28.65625 6.59375 39.40625 6.59375 \n",
       "Q 50.140625 6.59375 56.421875 14.59375 \n",
       "Q 62.703125 22.609375 62.703125 36.375 \n",
       "Q 62.703125 50.203125 56.421875 58.203125 \n",
       "Q 50.140625 66.21875 39.40625 66.21875 \n",
       "M 39.40625 74.21875 \n",
       "Q 54.734375 74.21875 63.90625 63.9375 \n",
       "Q 73.09375 53.65625 73.09375 36.375 \n",
       "Q 73.09375 19.140625 63.90625 8.859375 \n",
       "Q 54.734375 -1.421875 39.40625 -1.421875 \n",
       "Q 24.03125 -1.421875 14.8125 8.828125 \n",
       "Q 5.609375 19.09375 5.609375 36.375 \n",
       "Q 5.609375 53.65625 14.8125 63.9375 \n",
       "Q 24.03125 74.21875 39.40625 74.21875 \n",
       "\" id=\"BitstreamVeraSans-Roman-4f\"/>\n",
       "    </defs>\n",
       "    <g transform=\"translate(28.4617691929 97.2062450787)scale(0.18 -0.18)\">\n",
       "     <use xlink:href=\"#BitstreamVeraSans-Roman-4f\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"text_4\">\n",
       "    <!-- D -->\n",
       "    <defs>\n",
       "     <path d=\"M 19.671875 64.796875 \n",
       "L 19.671875 8.109375 \n",
       "L 31.59375 8.109375 \n",
       "Q 46.6875 8.109375 53.6875 14.9375 \n",
       "Q 60.6875 21.78125 60.6875 36.53125 \n",
       "Q 60.6875 51.171875 53.6875 57.984375 \n",
       "Q 46.6875 64.796875 31.59375 64.796875 \n",
       "z\n",
       "M 9.8125 72.90625 \n",
       "L 30.078125 72.90625 \n",
       "Q 51.265625 72.90625 61.171875 64.09375 \n",
       "Q 71.09375 55.28125 71.09375 36.53125 \n",
       "Q 71.09375 17.671875 61.125 8.828125 \n",
       "Q 51.171875 0 30.078125 0 \n",
       "L 9.8125 0 \n",
       "z\n",
       "\" id=\"BitstreamVeraSans-Roman-44\"/>\n",
       "    </defs>\n",
       "    <g transform=\"translate(28.6164566929 153.899158465)scale(0.18 -0.18)\">\n",
       "     <use xlink:href=\"#BitstreamVeraSans-Roman-44\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"text_5\">\n",
       "    <!-- S -->\n",
       "    <defs>\n",
       "     <path d=\"M 53.515625 70.515625 \n",
       "L 53.515625 60.890625 \n",
       "Q 47.90625 63.578125 42.921875 64.890625 \n",
       "Q 37.9375 66.21875 33.296875 66.21875 \n",
       "Q 25.25 66.21875 20.875 63.09375 \n",
       "Q 16.5 59.96875 16.5 54.203125 \n",
       "Q 16.5 49.359375 19.40625 46.890625 \n",
       "Q 22.3125 44.4375 30.421875 42.921875 \n",
       "L 36.375 41.703125 \n",
       "Q 47.40625 39.59375 52.65625 34.296875 \n",
       "Q 57.90625 29 57.90625 20.125 \n",
       "Q 57.90625 9.515625 50.796875 4.046875 \n",
       "Q 43.703125 -1.421875 29.984375 -1.421875 \n",
       "Q 24.8125 -1.421875 18.96875 -0.25 \n",
       "Q 13.140625 0.921875 6.890625 3.21875 \n",
       "L 6.890625 13.375 \n",
       "Q 12.890625 10.015625 18.65625 8.296875 \n",
       "Q 24.421875 6.59375 29.984375 6.59375 \n",
       "Q 38.421875 6.59375 43.015625 9.90625 \n",
       "Q 47.609375 13.234375 47.609375 19.390625 \n",
       "Q 47.609375 24.75 44.3125 27.78125 \n",
       "Q 41.015625 30.8125 33.5 32.328125 \n",
       "L 27.484375 33.5 \n",
       "Q 16.453125 35.6875 11.515625 40.375 \n",
       "Q 6.59375 45.0625 6.59375 53.421875 \n",
       "Q 6.59375 63.09375 13.40625 68.65625 \n",
       "Q 20.21875 74.21875 32.171875 74.21875 \n",
       "Q 37.3125 74.21875 42.625 73.28125 \n",
       "Q 47.953125 72.359375 53.515625 70.515625 \n",
       "\" id=\"BitstreamVeraSans-Roman-53\"/>\n",
       "    </defs>\n",
       "    <g transform=\"translate(86.5257763287 40.5133316929)scale(0.18 -0.18)\">\n",
       "     <use xlink:href=\"#BitstreamVeraSans-Roman-53\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "  </g>\n",
       " </g>\n",
       " <defs>\n",
       "  <clipPath id=\"pbd259e8e36\">\n",
       "   <rect height=\"170.078740157\" width=\"113.385826772\" x=\"7.2\" y=\"7.2\"/>\n",
       "  </clipPath>\n",
       " </defs>\n",
       "</svg>\n"
      ],
      "text/plain": [
       "<matplotlib.figure.Figure at 0x7feb96c8a358>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "pgm = daft.PGM([2, 3], origin=[-0.5, 0.5])\n",
    "add_node(pgm, 't', 'T', 0, 3)\n",
    "add_node(pgm, 's', 'S', 1, 3)\n",
    "add_node(pgm, 't_', 'T\\'', 1, 2)\n",
    "add_node(pgm, 'o', 'O', 0, 2)\n",
    "add_node(pgm, 'd', 'D', 0, 1)\n",
    "add_edges(pgm, [\n",
    "        ('t', 's'),\n",
    "        ('t', 't_'),\n",
    "        ('o', 't_'),\n",
    "        ('d', 't_')\n",
    "    ])\n",
    "pgm.render()\n",
    "save('bn_continuous_ex_02')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 50,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "image/svg+xml": [
       "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"no\"?>\n",
       "<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\n",
       "  \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n",
       "<!-- Created with matplotlib (http://matplotlib.org/) -->\n",
       "<svg height=\"127pt\" version=\"1.1\" viewBox=\"0 0 156 127\" width=\"156pt\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n",
       " <defs>\n",
       "  <style type=\"text/css\">\n",
       "*{stroke-linecap:butt;stroke-linejoin:round;stroke-miterlimit:100000;}\n",
       "  </style>\n",
       " </defs>\n",
       " <g id=\"figure_1\">\n",
       "  <g id=\"patch_1\">\n",
       "   <path d=\"M 0 127.785827 \n",
       "L 156.132283 127.785827 \n",
       "L 156.132283 0 \n",
       "L 0 0 \n",
       "L 0 127.785827 \n",
       "z\n",
       "\" style=\"fill:none;\"/>\n",
       "  </g>\n",
       "  <g id=\"axes_1\">\n",
       "   <g id=\"patch_2\">\n",
       "    <path clip-path=\"url(#pad42439ece)\" d=\"M 68.874404 68.874404 \n",
       "L 65.366709 68.373305 \n",
       "L 66.870007 66.870007 \n",
       "L 47.57284 47.57284 \n",
       "L 47.57284 47.57284 \n",
       "L 66.870007 66.870007 \n",
       "L 68.373305 65.366709 \n",
       "L 68.874404 68.874404 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_3\">\n",
       "    <path clip-path=\"url(#pad42439ece)\" d=\"M 80.900787 63.892913 \n",
       "L 78.774803 61.058268 \n",
       "L 80.900787 61.058268 \n",
       "L 80.900787 52.554331 \n",
       "L 80.900787 52.554331 \n",
       "L 80.900787 61.058268 \n",
       "L 83.026772 61.058268 \n",
       "L 80.900787 63.892913 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_4\">\n",
       "    <path clip-path=\"url(#pad42439ece)\" d=\"M 92.92717 68.874404 \n",
       "L 93.42827 65.366709 \n",
       "L 94.931568 66.870007 \n",
       "L 114.228735 47.57284 \n",
       "L 114.228735 47.57284 \n",
       "L 94.931568 66.870007 \n",
       "L 96.434866 68.373305 \n",
       "L 92.92717 68.874404 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_5\">\n",
       "    <path clip-path=\"url(#pad42439ece)\" d=\"M 126.255118 52.554331 \n",
       "C 130.765659 52.554331 135.092067 50.762274 138.281501 47.57284 \n",
       "C 141.470935 44.383406 143.262992 40.056998 143.262992 35.546457 \n",
       "C 143.262992 31.035916 141.470935 26.709508 138.281501 23.520074 \n",
       "C 135.092067 20.33064 130.765659 18.538583 126.255118 18.538583 \n",
       "C 121.744577 18.538583 117.418169 20.33064 114.228735 23.520074 \n",
       "C 111.039301 26.709508 109.247244 31.035916 109.247244 35.546457 \n",
       "C 109.247244 40.056998 111.039301 44.383406 114.228735 47.57284 \n",
       "C 117.418169 50.762274 121.744577 52.554331 126.255118 52.554331 \n",
       "L 126.255118 52.554331 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_6\">\n",
       "    <path clip-path=\"url(#pad42439ece)\" d=\"M 80.900787 97.908661 \n",
       "C 85.411328 97.908661 89.737736 96.116605 92.92717 92.92717 \n",
       "C 96.116605 89.737736 97.908661 85.411328 97.908661 80.900787 \n",
       "C 97.908661 76.390246 96.116605 72.063838 92.92717 68.874404 \n",
       "C 89.737736 65.68497 85.411328 63.892913 80.900787 63.892913 \n",
       "C 76.390246 63.892913 72.063838 65.68497 68.874404 68.874404 \n",
       "C 65.68497 72.063838 63.892913 76.390246 63.892913 80.900787 \n",
       "C 63.892913 85.411328 65.68497 89.737736 68.874404 92.92717 \n",
       "C 72.063838 96.116605 76.390246 97.908661 80.900787 97.908661 \n",
       "L 80.900787 97.908661 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_7\">\n",
       "    <path clip-path=\"url(#pad42439ece)\" d=\"M 80.900787 52.554331 \n",
       "C 85.411328 52.554331 89.737736 50.762274 92.92717 47.57284 \n",
       "C 96.116605 44.383406 97.908661 40.056998 97.908661 35.546457 \n",
       "C 97.908661 31.035916 96.116605 26.709508 92.92717 23.520074 \n",
       "C 89.737736 20.33064 85.411328 18.538583 80.900787 18.538583 \n",
       "C 76.390246 18.538583 72.063838 20.33064 68.874404 23.520074 \n",
       "C 65.68497 26.709508 63.892913 31.035916 63.892913 35.546457 \n",
       "C 63.892913 40.056998 65.68497 44.383406 68.874404 47.57284 \n",
       "C 72.063838 50.762274 76.390246 52.554331 80.900787 52.554331 \n",
       "L 80.900787 52.554331 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_8\">\n",
       "    <path clip-path=\"url(#pad42439ece)\" d=\"M 35.546457 52.554331 \n",
       "C 40.056998 52.554331 44.383406 50.762274 47.57284 47.57284 \n",
       "C 50.762274 44.383406 52.554331 40.056998 52.554331 35.546457 \n",
       "C 52.554331 31.035916 50.762274 26.709508 47.57284 23.520074 \n",
       "C 44.383406 20.33064 40.056998 18.538583 35.546457 18.538583 \n",
       "C 31.035916 18.538583 26.709508 20.33064 23.520074 23.520074 \n",
       "C 20.33064 26.709508 18.538583 31.035916 18.538583 35.546457 \n",
       "C 18.538583 40.056998 20.33064 44.383406 23.520074 47.57284 \n",
       "C 26.709508 50.762274 31.035916 52.554331 35.546457 52.554331 \n",
       "L 35.546457 52.554331 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"matplotlib.axis_1\"/>\n",
       "   <g id=\"matplotlib.axis_2\"/>\n",
       "   <g id=\"text_1\">\n",
       "    <!-- $x_n$ -->\n",
       "    <defs>\n",
       "     <path d=\"M 54.40625 45.296875 \n",
       "L 34.40625 23.59375 \n",
       "L 45.203125 0 \n",
       "L 35.796875 0 \n",
       "L 27.90625 17.5 \n",
       "L 12.40625 0 \n",
       "L 3 0 \n",
       "L 25 23.90625 \n",
       "L 15.40625 45.296875 \n",
       "L 24.796875 45.296875 \n",
       "L 31.59375 30.203125 \n",
       "L 45 45.296875 \n",
       "z\n",
       "\" id=\"STIXGeneral-Italic-1d639\"/>\n",
       "     <path d=\"M 25.09375 45.90625 \n",
       "L 23.90625 40.203125 \n",
       "Q 28.40625 43.796875 32.203125 45.046875 \n",
       "Q 36 46.296875 40.5 46.296875 \n",
       "Q 45.203125 46.296875 48.09375 43.75 \n",
       "Q 51 41.203125 51 37.203125 \n",
       "Q 51 34.796875 50.40625 32.09375 \n",
       "L 42.40625 0 \n",
       "L 34.5 0 \n",
       "L 42 30.40625 \n",
       "Q 42.5 32.59375 42.5 33.90625 \n",
       "Q 42.5 39.203125 36 39.203125 \n",
       "Q 33.09375 39.203125 28.640625 36.703125 \n",
       "Q 24.203125 34.203125 21.703125 30.203125 \n",
       "L 14.203125 0 \n",
       "L 6.296875 0 \n",
       "L 17.203125 44 \n",
       "L 24.296875 46.40625 \n",
       "z\n",
       "\" id=\"STIXGeneral-Italic-1d62f\"/>\n",
       "    </defs>\n",
       "    <g transform=\"translate(118.60511811 40.5133316929)scale(0.18 -0.18)\">\n",
       "     <use transform=\"translate(0.0 0.703125)\" xlink:href=\"#STIXGeneral-Italic-1d639\"/>\n",
       "     <use transform=\"translate(48.19999694824219 -12.885937499999997)scale(0.7)\" xlink:href=\"#STIXGeneral-Italic-1d62f\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"text_2\">\n",
       "    <!-- $Y$ -->\n",
       "    <defs>\n",
       "     <path d=\"M 77.40625 66.203125 \n",
       "L 43 28.796875 \n",
       "L 35.796875 0 \n",
       "L 27.09375 0 \n",
       "L 34.203125 28.796875 \n",
       "L 18.59375 66.203125 \n",
       "L 28.09375 66.203125 \n",
       "L 40.5 36.203125 \n",
       "L 67.90625 66.203125 \n",
       "z\n",
       "\" id=\"STIXGeneral-Italic-1d620\"/>\n",
       "    </defs>\n",
       "    <g transform=\"translate(75.2307874016 85.8676624016)scale(0.18 -0.18)\">\n",
       "     <use transform=\"translate(0.0 0.796875)\" xlink:href=\"#STIXGeneral-Italic-1d620\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"text_3\">\n",
       "    <!-- $\\dots$ -->\n",
       "    <defs>\n",
       "     <path d=\"M 88.796875 4.296875 \n",
       "Q 88.796875 2.09375 87.140625 0.5 \n",
       "Q 85.5 -1.09375 83.203125 -1.09375 \n",
       "Q 80.90625 -1.09375 79.296875 0.5 \n",
       "Q 77.703125 2.09375 77.703125 4.390625 \n",
       "Q 77.703125 6.703125 79.34375 8.34375 \n",
       "Q 81 10 83.296875 10 \n",
       "Q 85.5 10 87.140625 8.296875 \n",
       "Q 88.796875 6.59375 88.796875 4.296875 \n",
       "M 55.5 4.296875 \n",
       "Q 55.5 2.09375 53.84375 0.5 \n",
       "Q 52.203125 -1.09375 49.890625 -1.09375 \n",
       "Q 47.59375 -1.09375 46 0.5 \n",
       "Q 44.40625 2.09375 44.40625 4.390625 \n",
       "Q 44.40625 6.703125 46.046875 8.34375 \n",
       "Q 47.703125 10 50 10 \n",
       "Q 52.203125 10 53.84375 8.296875 \n",
       "Q 55.5 6.59375 55.5 4.296875 \n",
       "M 22.203125 4.296875 \n",
       "Q 22.203125 2.09375 20.546875 0.5 \n",
       "Q 18.90625 -1.09375 16.59375 -1.09375 \n",
       "Q 14.296875 -1.09375 12.6875 0.5 \n",
       "Q 11.09375 2.09375 11.09375 4.390625 \n",
       "Q 11.09375 6.703125 12.75 8.34375 \n",
       "Q 14.40625 10 16.703125 10 \n",
       "Q 18.90625 10 20.546875 8.296875 \n",
       "Q 22.203125 6.59375 22.203125 4.296875 \n",
       "\" id=\"STIXGeneral-Regular-2026\"/>\n",
       "    </defs>\n",
       "    <g transform=\"translate(71.9007874016 40.5133316929)scale(0.18 -0.18)\">\n",
       "     <use xlink:href=\"#STIXGeneral-Regular-2026\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"text_4\">\n",
       "    <!-- $x_1$ -->\n",
       "    <defs>\n",
       "     <path d=\"M 30.203125 0 \n",
       "L 22.296875 0 \n",
       "L 22.296875 57 \n",
       "Q 20.09375 56 15.75 53.75 \n",
       "Q 11.40625 51.5 10.796875 51.203125 \n",
       "L 10.796875 58.5 \n",
       "L 28.796875 67.703125 \n",
       "L 30.203125 67.203125 \n",
       "z\n",
       "\" id=\"STIXGeneral-Regular-1d7e3\"/>\n",
       "    </defs>\n",
       "    <g transform=\"translate(27.8064566929 40.5133316929)scale(0.18 -0.18)\">\n",
       "     <use transform=\"translate(0.0 0.703125)\" xlink:href=\"#STIXGeneral-Italic-1d639\"/>\n",
       "     <use transform=\"translate(48.19999694824219 -12.885937499999997)scale(0.7)\" xlink:href=\"#STIXGeneral-Regular-1d7e3\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "  </g>\n",
       " </g>\n",
       " <defs>\n",
       "  <clipPath id=\"pad42439ece\">\n",
       "   <rect height=\"113.385826772\" width=\"141.732283465\" x=\"7.2\" y=\"7.2\"/>\n",
       "  </clipPath>\n",
       " </defs>\n",
       "</svg>\n"
      ],
      "text/plain": [
       "<matplotlib.figure.Figure at 0x7feb96d72908>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "pgm = daft.PGM([2.5, 2], origin=[-0.5, 0.5])\n",
    "add_node(pgm, 'x1', '$x_1$', 0, 2)\n",
    "add_node(pgm, 'x', r'$\\dots$', 0.8, 2)\n",
    "add_node(pgm, 'xn', '$x_n$', 1.6, 2)\n",
    "add_node(pgm, 'Y', '$Y$', 0.8, 1.2)\n",
    "add_edges(pgm, [\n",
    "        ('x1', 'Y'),\n",
    "        ('x', 'Y'),\n",
    "        ('xn', 'Y'),\n",
    "    ])\n",
    "pgm.render()\n",
    "save('bn_linear_gaussian')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 51,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "image/svg+xml": [
       "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"no\"?>\n",
       "<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\n",
       "  \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n",
       "<!-- Created with matplotlib (http://matplotlib.org/) -->\n",
       "<svg height=\"127pt\" version=\"1.1\" viewBox=\"0 0 156 127\" width=\"156pt\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n",
       " <defs>\n",
       "  <style type=\"text/css\">\n",
       "*{stroke-linecap:butt;stroke-linejoin:round;stroke-miterlimit:100000;}\n",
       "  </style>\n",
       " </defs>\n",
       " <g id=\"figure_1\">\n",
       "  <g id=\"patch_1\">\n",
       "   <path d=\"M 0 127.785827 \n",
       "L 156.132283 127.785827 \n",
       "L 156.132283 0 \n",
       "L 0 0 \n",
       "L 0 127.785827 \n",
       "z\n",
       "\" style=\"fill:none;\"/>\n",
       "  </g>\n",
       "  <g id=\"axes_1\">\n",
       "   <g id=\"patch_2\">\n",
       "    <path clip-path=\"url(#p6cacc47644)\" d=\"M 68.874404 68.874404 \n",
       "L 65.366709 68.373305 \n",
       "L 66.870007 66.870007 \n",
       "L 47.57284 47.57284 \n",
       "L 47.57284 47.57284 \n",
       "L 66.870007 66.870007 \n",
       "L 68.373305 65.366709 \n",
       "L 68.874404 68.874404 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_3\">\n",
       "    <path clip-path=\"url(#p6cacc47644)\" d=\"M 80.900787 63.892913 \n",
       "L 78.774803 61.058268 \n",
       "L 80.900787 61.058268 \n",
       "L 80.900787 52.554331 \n",
       "L 80.900787 52.554331 \n",
       "L 80.900787 61.058268 \n",
       "L 83.026772 61.058268 \n",
       "L 80.900787 63.892913 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_4\">\n",
       "    <path clip-path=\"url(#p6cacc47644)\" d=\"M 92.92717 68.874404 \n",
       "L 93.42827 65.366709 \n",
       "L 94.931568 66.870007 \n",
       "L 114.228735 47.57284 \n",
       "L 114.228735 47.57284 \n",
       "L 94.931568 66.870007 \n",
       "L 96.434866 68.373305 \n",
       "L 92.92717 68.874404 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_5\">\n",
       "    <path clip-path=\"url(#p6cacc47644)\" d=\"M 70.276053 67.619869 \n",
       "L 66.845149 66.734475 \n",
       "L 68.505264 65.406383 \n",
       "L 46.171191 37.488792 \n",
       "L 46.171191 37.488792 \n",
       "L 68.505264 65.406383 \n",
       "L 70.165378 64.078291 \n",
       "L 70.276053 67.619869 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_6\">\n",
       "    <path clip-path=\"url(#p6cacc47644)\" d=\"M 126.255118 52.554331 \n",
       "C 130.765659 52.554331 135.092067 50.762274 138.281501 47.57284 \n",
       "C 141.470935 44.383406 143.262992 40.056998 143.262992 35.546457 \n",
       "C 143.262992 31.035916 141.470935 26.709508 138.281501 23.520074 \n",
       "C 135.092067 20.33064 130.765659 18.538583 126.255118 18.538583 \n",
       "C 121.744577 18.538583 117.418169 20.33064 114.228735 23.520074 \n",
       "C 111.039301 26.709508 109.247244 31.035916 109.247244 35.546457 \n",
       "C 109.247244 40.056998 111.039301 44.383406 114.228735 47.57284 \n",
       "C 117.418169 50.762274 121.744577 52.554331 126.255118 52.554331 \n",
       "L 126.255118 52.554331 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_7\">\n",
       "    <path clip-path=\"url(#p6cacc47644)\" d=\"M 80.900787 97.908661 \n",
       "C 85.411328 97.908661 89.737736 96.116605 92.92717 92.92717 \n",
       "C 96.116605 89.737736 97.908661 85.411328 97.908661 80.900787 \n",
       "C 97.908661 76.390246 96.116605 72.063838 92.92717 68.874404 \n",
       "C 89.737736 65.68497 85.411328 63.892913 80.900787 63.892913 \n",
       "C 76.390246 63.892913 72.063838 65.68497 68.874404 68.874404 \n",
       "C 65.68497 72.063838 63.892913 76.390246 63.892913 80.900787 \n",
       "C 63.892913 85.411328 65.68497 89.737736 68.874404 92.92717 \n",
       "C 72.063838 96.116605 76.390246 97.908661 80.900787 97.908661 \n",
       "L 80.900787 97.908661 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_8\">\n",
       "    <path clip-path=\"url(#p6cacc47644)\" d=\"M 80.900787 52.554331 \n",
       "C 85.411328 52.554331 89.737736 50.762274 92.92717 47.57284 \n",
       "C 96.116605 44.383406 97.908661 40.056998 97.908661 35.546457 \n",
       "C 97.908661 31.035916 96.116605 26.709508 92.92717 23.520074 \n",
       "C 89.737736 20.33064 85.411328 18.538583 80.900787 18.538583 \n",
       "C 76.390246 18.538583 72.063838 20.33064 68.874404 23.520074 \n",
       "C 65.68497 26.709508 63.892913 31.035916 63.892913 35.546457 \n",
       "C 63.892913 40.056998 65.68497 44.383406 68.874404 47.57284 \n",
       "C 72.063838 50.762274 76.390246 52.554331 80.900787 52.554331 \n",
       "L 80.900787 52.554331 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_9\">\n",
       "    <path clip-path=\"url(#p6cacc47644)\" d=\"M 35.546457 41.215748 \n",
       "C 40.056998 41.215748 44.383406 39.423691 47.57284 36.234257 \n",
       "C 50.762274 33.044823 52.554331 28.718415 52.554331 24.207874 \n",
       "C 52.554331 19.697333 50.762274 15.370925 47.57284 12.181491 \n",
       "C 44.383406 8.992057 40.056998 7.2 35.546457 7.2 \n",
       "C 31.035916 7.2 26.709508 8.992057 23.520074 12.181491 \n",
       "C 20.33064 15.370925 18.538583 19.697333 18.538583 24.207874 \n",
       "C 18.538583 28.718415 20.33064 33.044823 23.520074 36.234257 \n",
       "C 26.709508 39.423691 31.035916 41.215748 35.546457 41.215748 \n",
       "L 35.546457 41.215748 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_10\">\n",
       "    <path clip-path=\"url(#p6cacc47644)\" d=\"M 35.546457 52.554331 \n",
       "C 40.056998 52.554331 44.383406 50.762274 47.57284 47.57284 \n",
       "C 50.762274 44.383406 52.554331 40.056998 52.554331 35.546457 \n",
       "C 52.554331 31.035916 50.762274 26.709508 47.57284 23.520074 \n",
       "C 44.383406 20.33064 40.056998 18.538583 35.546457 18.538583 \n",
       "C 31.035916 18.538583 26.709508 20.33064 23.520074 23.520074 \n",
       "C 20.33064 26.709508 18.538583 31.035916 18.538583 35.546457 \n",
       "C 18.538583 40.056998 20.33064 44.383406 23.520074 47.57284 \n",
       "C 26.709508 50.762274 31.035916 52.554331 35.546457 52.554331 \n",
       "L 35.546457 52.554331 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"matplotlib.axis_1\"/>\n",
       "   <g id=\"matplotlib.axis_2\"/>\n",
       "   <g id=\"text_1\">\n",
       "    <!-- $x_n$ -->\n",
       "    <defs>\n",
       "     <path d=\"M 54.40625 45.296875 \n",
       "L 34.40625 23.59375 \n",
       "L 45.203125 0 \n",
       "L 35.796875 0 \n",
       "L 27.90625 17.5 \n",
       "L 12.40625 0 \n",
       "L 3 0 \n",
       "L 25 23.90625 \n",
       "L 15.40625 45.296875 \n",
       "L 24.796875 45.296875 \n",
       "L 31.59375 30.203125 \n",
       "L 45 45.296875 \n",
       "z\n",
       "\" id=\"STIXGeneral-Italic-1d639\"/>\n",
       "     <path d=\"M 25.09375 45.90625 \n",
       "L 23.90625 40.203125 \n",
       "Q 28.40625 43.796875 32.203125 45.046875 \n",
       "Q 36 46.296875 40.5 46.296875 \n",
       "Q 45.203125 46.296875 48.09375 43.75 \n",
       "Q 51 41.203125 51 37.203125 \n",
       "Q 51 34.796875 50.40625 32.09375 \n",
       "L 42.40625 0 \n",
       "L 34.5 0 \n",
       "L 42 30.40625 \n",
       "Q 42.5 32.59375 42.5 33.90625 \n",
       "Q 42.5 39.203125 36 39.203125 \n",
       "Q 33.09375 39.203125 28.640625 36.703125 \n",
       "Q 24.203125 34.203125 21.703125 30.203125 \n",
       "L 14.203125 0 \n",
       "L 6.296875 0 \n",
       "L 17.203125 44 \n",
       "L 24.296875 46.40625 \n",
       "z\n",
       "\" id=\"STIXGeneral-Italic-1d62f\"/>\n",
       "    </defs>\n",
       "    <g transform=\"translate(118.60511811 40.5133316929)scale(0.18 -0.18)\">\n",
       "     <use transform=\"translate(0.0 0.703125)\" xlink:href=\"#STIXGeneral-Italic-1d639\"/>\n",
       "     <use transform=\"translate(48.19999694824219 -12.885937499999997)scale(0.7)\" xlink:href=\"#STIXGeneral-Italic-1d62f\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"text_2\">\n",
       "    <!-- $Y$ -->\n",
       "    <defs>\n",
       "     <path d=\"M 77.40625 66.203125 \n",
       "L 43 28.796875 \n",
       "L 35.796875 0 \n",
       "L 27.09375 0 \n",
       "L 34.203125 28.796875 \n",
       "L 18.59375 66.203125 \n",
       "L 28.09375 66.203125 \n",
       "L 40.5 36.203125 \n",
       "L 67.90625 66.203125 \n",
       "z\n",
       "\" id=\"STIXGeneral-Italic-1d620\"/>\n",
       "    </defs>\n",
       "    <g transform=\"translate(75.2307874016 85.8676624016)scale(0.18 -0.18)\">\n",
       "     <use transform=\"translate(0.0 0.796875)\" xlink:href=\"#STIXGeneral-Italic-1d620\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"text_3\">\n",
       "    <!-- $\\dots$ -->\n",
       "    <defs>\n",
       "     <path d=\"M 88.796875 4.296875 \n",
       "Q 88.796875 2.09375 87.140625 0.5 \n",
       "Q 85.5 -1.09375 83.203125 -1.09375 \n",
       "Q 80.90625 -1.09375 79.296875 0.5 \n",
       "Q 77.703125 2.09375 77.703125 4.390625 \n",
       "Q 77.703125 6.703125 79.34375 8.34375 \n",
       "Q 81 10 83.296875 10 \n",
       "Q 85.5 10 87.140625 8.296875 \n",
       "Q 88.796875 6.59375 88.796875 4.296875 \n",
       "M 55.5 4.296875 \n",
       "Q 55.5 2.09375 53.84375 0.5 \n",
       "Q 52.203125 -1.09375 49.890625 -1.09375 \n",
       "Q 47.59375 -1.09375 46 0.5 \n",
       "Q 44.40625 2.09375 44.40625 4.390625 \n",
       "Q 44.40625 6.703125 46.046875 8.34375 \n",
       "Q 47.703125 10 50 10 \n",
       "Q 52.203125 10 53.84375 8.296875 \n",
       "Q 55.5 6.59375 55.5 4.296875 \n",
       "M 22.203125 4.296875 \n",
       "Q 22.203125 2.09375 20.546875 0.5 \n",
       "Q 18.90625 -1.09375 16.59375 -1.09375 \n",
       "Q 14.296875 -1.09375 12.6875 0.5 \n",
       "Q 11.09375 2.09375 11.09375 4.390625 \n",
       "Q 11.09375 6.703125 12.75 8.34375 \n",
       "Q 14.40625 10 16.703125 10 \n",
       "Q 18.90625 10 20.546875 8.296875 \n",
       "Q 22.203125 6.59375 22.203125 4.296875 \n",
       "\" id=\"STIXGeneral-Regular-2026\"/>\n",
       "    </defs>\n",
       "    <g transform=\"translate(71.9007874016 40.5133316929)scale(0.18 -0.18)\">\n",
       "     <use xlink:href=\"#STIXGeneral-Regular-2026\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"text_4\">\n",
       "    <!-- $A$ -->\n",
       "    <defs>\n",
       "     <path d=\"M 63.5 0 \n",
       "L 53.90625 0 \n",
       "L 50.59375 20 \n",
       "L 25.703125 20 \n",
       "L 12.703125 0 \n",
       "L 3.09375 0 \n",
       "L 48.796875 67.40625 \n",
       "L 51.40625 67.40625 \n",
       "z\n",
       "M 49.5 27.40625 \n",
       "L 45.796875 50.296875 \n",
       "L 30.703125 27.40625 \n",
       "z\n",
       "\" id=\"STIXGeneral-Italic-1d608\"/>\n",
       "    </defs>\n",
       "    <g transform=\"translate(29.5164566929 29.1747490157)scale(0.18 -0.18)\">\n",
       "     <use transform=\"translate(0.0 0.59375)\" xlink:href=\"#STIXGeneral-Italic-1d608\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"text_5\">\n",
       "    <!-- $x_1$ -->\n",
       "    <defs>\n",
       "     <path d=\"M 30.203125 0 \n",
       "L 22.296875 0 \n",
       "L 22.296875 57 \n",
       "Q 20.09375 56 15.75 53.75 \n",
       "Q 11.40625 51.5 10.796875 51.203125 \n",
       "L 10.796875 58.5 \n",
       "L 28.796875 67.703125 \n",
       "L 30.203125 67.203125 \n",
       "z\n",
       "\" id=\"STIXGeneral-Regular-1d7e3\"/>\n",
       "    </defs>\n",
       "    <g transform=\"translate(27.8064566929 40.5133316929)scale(0.18 -0.18)\">\n",
       "     <use transform=\"translate(0.0 0.703125)\" xlink:href=\"#STIXGeneral-Italic-1d639\"/>\n",
       "     <use transform=\"translate(48.19999694824219 -12.885937499999997)scale(0.7)\" xlink:href=\"#STIXGeneral-Regular-1d7e3\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "  </g>\n",
       " </g>\n",
       " <defs>\n",
       "  <clipPath id=\"p6cacc47644\">\n",
       "   <rect height=\"113.385826772\" width=\"141.732283465\" x=\"7.2\" y=\"7.2\"/>\n",
       "  </clipPath>\n",
       " </defs>\n",
       "</svg>\n"
      ],
      "text/plain": [
       "<matplotlib.figure.Figure at 0x7feb96d72748>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "pgm = daft.PGM([2.5, 2], origin=[-0.5, 0.5])\n",
    "add_node(pgm, 'x1', '$x_1$', 0, 2)\n",
    "add_node(pgm, 'x', r'$\\dots$', 0.8, 2)\n",
    "add_node(pgm, 'xn', '$x_n$', 1.6, 2)\n",
    "add_node(pgm, 'Y', '$Y$', 0.8, 1.2)\n",
    "add_node(pgm, 'A', '$A$', 0, 2.2)\n",
    "add_edges(pgm, [\n",
    "        ('x1', 'Y'),\n",
    "        ('x', 'Y'),\n",
    "        ('xn', 'Y'),\n",
    "        ('A', 'Y')\n",
    "    ])\n",
    "pgm.render()\n",
    "save('bn_conditional_linear_gaussian')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 52,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "image/svg+xml": [
       "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"no\"?>\n",
       "<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\n",
       "  \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n",
       "<!-- Created with matplotlib (http://matplotlib.org/) -->\n",
       "<svg height=\"127pt\" version=\"1.1\" viewBox=\"0 0 127 127\" width=\"127pt\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n",
       " <defs>\n",
       "  <style type=\"text/css\">\n",
       "*{stroke-linecap:butt;stroke-linejoin:round;stroke-miterlimit:100000;}\n",
       "  </style>\n",
       " </defs>\n",
       " <g id=\"figure_1\">\n",
       "  <g id=\"patch_1\">\n",
       "   <path d=\"M 0 127.785827 \n",
       "L 127.785827 127.785827 \n",
       "L 127.785827 0 \n",
       "L 0 0 \n",
       "L 0 127.785827 \n",
       "z\n",
       "\" style=\"fill:none;\"/>\n",
       "  </g>\n",
       "  <g id=\"axes_1\">\n",
       "   <g id=\"patch_2\">\n",
       "    <path clip-path=\"url(#pc2bb445a41)\" d=\"M 63.892913 52.554331 \n",
       "C 68.403454 52.554331 72.729862 50.762274 75.919296 47.57284 \n",
       "C 79.108731 44.383406 80.900787 40.056998 80.900787 35.546457 \n",
       "C 80.900787 31.035916 79.108731 26.709508 75.919296 23.520074 \n",
       "C 72.729862 20.33064 68.403454 18.538583 63.892913 18.538583 \n",
       "C 59.382372 18.538583 55.055964 20.33064 51.86653 23.520074 \n",
       "C 48.677096 26.709508 46.885039 31.035916 46.885039 35.546457 \n",
       "C 46.885039 40.056998 48.677096 44.383406 51.86653 47.57284 \n",
       "C 55.055964 50.762274 59.382372 52.554331 63.892913 52.554331 \n",
       "L 63.892913 52.554331 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_3\">\n",
       "    <path clip-path=\"url(#pc2bb445a41)\" d=\"M 35.546457 80.900787 \n",
       "C 40.056998 80.900787 44.383406 79.108731 47.57284 75.919296 \n",
       "C 50.762274 72.729862 52.554331 68.403454 52.554331 63.892913 \n",
       "C 52.554331 59.382372 50.762274 55.055964 47.57284 51.86653 \n",
       "C 44.383406 48.677096 40.056998 46.885039 35.546457 46.885039 \n",
       "C 31.035916 46.885039 26.709508 48.677096 23.520074 51.86653 \n",
       "C 20.33064 55.055964 18.538583 59.382372 18.538583 63.892913 \n",
       "C 18.538583 68.403454 20.33064 72.729862 23.520074 75.919296 \n",
       "C 26.709508 79.108731 31.035916 80.900787 35.546457 80.900787 \n",
       "L 35.546457 80.900787 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_4\">\n",
       "    <path clip-path=\"url(#pc2bb445a41)\" d=\"M 92.23937 80.900787 \n",
       "C 96.749911 80.900787 101.076319 79.108731 104.265753 75.919296 \n",
       "C 107.455187 72.729862 109.247244 68.403454 109.247244 63.892913 \n",
       "C 109.247244 59.382372 107.455187 55.055964 104.265753 51.86653 \n",
       "C 101.076319 48.677096 96.749911 46.885039 92.23937 46.885039 \n",
       "C 87.728829 46.885039 83.402421 48.677096 80.212987 51.86653 \n",
       "C 77.023553 55.055964 75.231496 59.382372 75.231496 63.892913 \n",
       "C 75.231496 68.403454 77.023553 72.729862 80.212987 75.919296 \n",
       "C 83.402421 79.108731 87.728829 80.900787 92.23937 80.900787 \n",
       "L 92.23937 80.900787 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_5\">\n",
       "    <path clip-path=\"url(#pc2bb445a41)\" d=\"M 63.892913 109.247244 \n",
       "C 68.403454 109.247244 72.729862 107.455187 75.919296 104.265753 \n",
       "C 79.108731 101.076319 80.900787 96.749911 80.900787 92.23937 \n",
       "C 80.900787 87.728829 79.108731 83.402421 75.919296 80.212987 \n",
       "C 72.729862 77.023553 68.403454 75.231496 63.892913 75.231496 \n",
       "C 59.382372 75.231496 55.055964 77.023553 51.86653 80.212987 \n",
       "C 48.677096 83.402421 46.885039 87.728829 46.885039 92.23937 \n",
       "C 46.885039 96.749911 48.677096 101.076319 51.86653 104.265753 \n",
       "C 55.055964 107.455187 59.382372 109.247244 63.892913 109.247244 \n",
       "L 63.892913 109.247244 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"line2d_1\">\n",
       "    <path clip-path=\"url(#pc2bb445a41)\" d=\"M 75.919296 47.57284 \n",
       "L 80.212987 51.86653 \n",
       "\" style=\"fill:none;stroke:#000000;stroke-linecap:square;\"/>\n",
       "   </g>\n",
       "   <g id=\"line2d_2\">\n",
       "    <path clip-path=\"url(#pc2bb445a41)\" d=\"M 47.57284 51.86653 \n",
       "L 51.86653 47.57284 \n",
       "\" style=\"fill:none;stroke:#000000;stroke-linecap:square;\"/>\n",
       "   </g>\n",
       "   <g id=\"line2d_3\">\n",
       "    <path clip-path=\"url(#pc2bb445a41)\" d=\"M 80.212987 75.919296 \n",
       "L 75.919296 80.212987 \n",
       "\" style=\"fill:none;stroke:#000000;stroke-linecap:square;\"/>\n",
       "   </g>\n",
       "   <g id=\"line2d_4\">\n",
       "    <path clip-path=\"url(#pc2bb445a41)\" d=\"M 51.86653 80.212987 \n",
       "L 47.57284 75.919296 \n",
       "\" style=\"fill:none;stroke:#000000;stroke-linecap:square;\"/>\n",
       "   </g>\n",
       "   <g id=\"matplotlib.axis_1\"/>\n",
       "   <g id=\"matplotlib.axis_2\"/>\n",
       "   <g id=\"text_1\">\n",
       "    <!-- Alice -->\n",
       "    <defs>\n",
       "     <path d=\"M 9.421875 54.6875 \n",
       "L 18.40625 54.6875 \n",
       "L 18.40625 0 \n",
       "L 9.421875 0 \n",
       "z\n",
       "M 9.421875 75.984375 \n",
       "L 18.40625 75.984375 \n",
       "L 18.40625 64.59375 \n",
       "L 9.421875 64.59375 \n",
       "z\n",
       "\" id=\"BitstreamVeraSans-Roman-69\"/>\n",
       "     <path d=\"M 48.78125 52.59375 \n",
       "L 48.78125 44.1875 \n",
       "Q 44.96875 46.296875 41.140625 47.34375 \n",
       "Q 37.3125 48.390625 33.40625 48.390625 \n",
       "Q 24.65625 48.390625 19.8125 42.84375 \n",
       "Q 14.984375 37.3125 14.984375 27.296875 \n",
       "Q 14.984375 17.28125 19.8125 11.734375 \n",
       "Q 24.65625 6.203125 33.40625 6.203125 \n",
       "Q 37.3125 6.203125 41.140625 7.25 \n",
       "Q 44.96875 8.296875 48.78125 10.40625 \n",
       "L 48.78125 2.09375 \n",
       "Q 45.015625 0.34375 40.984375 -0.53125 \n",
       "Q 36.96875 -1.421875 32.421875 -1.421875 \n",
       "Q 20.0625 -1.421875 12.78125 6.34375 \n",
       "Q 5.515625 14.109375 5.515625 27.296875 \n",
       "Q 5.515625 40.671875 12.859375 48.328125 \n",
       "Q 20.21875 56 33.015625 56 \n",
       "Q 37.15625 56 41.109375 55.140625 \n",
       "Q 45.0625 54.296875 48.78125 52.59375 \n",
       "\" id=\"BitstreamVeraSans-Roman-63\"/>\n",
       "     <path d=\"M 9.421875 75.984375 \n",
       "L 18.40625 75.984375 \n",
       "L 18.40625 0 \n",
       "L 9.421875 0 \n",
       "z\n",
       "\" id=\"BitstreamVeraSans-Roman-6c\"/>\n",
       "     <path d=\"M 56.203125 29.59375 \n",
       "L 56.203125 25.203125 \n",
       "L 14.890625 25.203125 \n",
       "Q 15.484375 15.921875 20.484375 11.0625 \n",
       "Q 25.484375 6.203125 34.421875 6.203125 \n",
       "Q 39.59375 6.203125 44.453125 7.46875 \n",
       "Q 49.3125 8.734375 54.109375 11.28125 \n",
       "L 54.109375 2.78125 \n",
       "Q 49.265625 0.734375 44.1875 -0.34375 \n",
       "Q 39.109375 -1.421875 33.890625 -1.421875 \n",
       "Q 20.796875 -1.421875 13.15625 6.1875 \n",
       "Q 5.515625 13.8125 5.515625 26.8125 \n",
       "Q 5.515625 40.234375 12.765625 48.109375 \n",
       "Q 20.015625 56 32.328125 56 \n",
       "Q 43.359375 56 49.78125 48.890625 \n",
       "Q 56.203125 41.796875 56.203125 29.59375 \n",
       "M 47.21875 32.234375 \n",
       "Q 47.125 39.59375 43.09375 43.984375 \n",
       "Q 39.0625 48.390625 32.421875 48.390625 \n",
       "Q 24.90625 48.390625 20.390625 44.140625 \n",
       "Q 15.875 39.890625 15.1875 32.171875 \n",
       "z\n",
       "\" id=\"BitstreamVeraSans-Roman-65\"/>\n",
       "     <path d=\"M 34.1875 63.1875 \n",
       "L 20.796875 26.90625 \n",
       "L 47.609375 26.90625 \n",
       "z\n",
       "M 28.609375 72.90625 \n",
       "L 39.796875 72.90625 \n",
       "L 67.578125 0 \n",
       "L 57.328125 0 \n",
       "L 50.6875 18.703125 \n",
       "L 17.828125 18.703125 \n",
       "L 11.1875 0 \n",
       "L 0.78125 0 \n",
       "z\n",
       "\" id=\"BitstreamVeraSans-Roman-41\"/>\n",
       "    </defs>\n",
       "    <g transform=\"translate(54.2735383858 37.7539566929)scale(0.08 -0.08)\">\n",
       "     <use xlink:href=\"#BitstreamVeraSans-Roman-41\"/>\n",
       "     <use x=\"68.408203125\" xlink:href=\"#BitstreamVeraSans-Roman-6c\"/>\n",
       "     <use x=\"96.19140625\" xlink:href=\"#BitstreamVeraSans-Roman-69\"/>\n",
       "     <use x=\"123.974609375\" xlink:href=\"#BitstreamVeraSans-Roman-63\"/>\n",
       "     <use x=\"178.955078125\" xlink:href=\"#BitstreamVeraSans-Roman-65\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"text_2\">\n",
       "    <!-- Debbie -->\n",
       "    <defs>\n",
       "     <path d=\"M 19.671875 64.796875 \n",
       "L 19.671875 8.109375 \n",
       "L 31.59375 8.109375 \n",
       "Q 46.6875 8.109375 53.6875 14.9375 \n",
       "Q 60.6875 21.78125 60.6875 36.53125 \n",
       "Q 60.6875 51.171875 53.6875 57.984375 \n",
       "Q 46.6875 64.796875 31.59375 64.796875 \n",
       "z\n",
       "M 9.8125 72.90625 \n",
       "L 30.078125 72.90625 \n",
       "Q 51.265625 72.90625 61.171875 64.09375 \n",
       "Q 71.09375 55.28125 71.09375 36.53125 \n",
       "Q 71.09375 17.671875 61.125 8.828125 \n",
       "Q 51.171875 0 30.078125 0 \n",
       "L 9.8125 0 \n",
       "z\n",
       "\" id=\"BitstreamVeraSans-Roman-44\"/>\n",
       "     <path d=\"M 48.6875 27.296875 \n",
       "Q 48.6875 37.203125 44.609375 42.84375 \n",
       "Q 40.53125 48.484375 33.40625 48.484375 \n",
       "Q 26.265625 48.484375 22.1875 42.84375 \n",
       "Q 18.109375 37.203125 18.109375 27.296875 \n",
       "Q 18.109375 17.390625 22.1875 11.75 \n",
       "Q 26.265625 6.109375 33.40625 6.109375 \n",
       "Q 40.53125 6.109375 44.609375 11.75 \n",
       "Q 48.6875 17.390625 48.6875 27.296875 \n",
       "M 18.109375 46.390625 \n",
       "Q 20.953125 51.265625 25.265625 53.625 \n",
       "Q 29.59375 56 35.59375 56 \n",
       "Q 45.5625 56 51.78125 48.09375 \n",
       "Q 58.015625 40.1875 58.015625 27.296875 \n",
       "Q 58.015625 14.40625 51.78125 6.484375 \n",
       "Q 45.5625 -1.421875 35.59375 -1.421875 \n",
       "Q 29.59375 -1.421875 25.265625 0.953125 \n",
       "Q 20.953125 3.328125 18.109375 8.203125 \n",
       "L 18.109375 0 \n",
       "L 9.078125 0 \n",
       "L 9.078125 75.984375 \n",
       "L 18.109375 75.984375 \n",
       "z\n",
       "\" id=\"BitstreamVeraSans-Roman-62\"/>\n",
       "    </defs>\n",
       "    <g transform=\"translate(21.3539566929 66.1004133858)scale(0.08 -0.08)\">\n",
       "     <use xlink:href=\"#BitstreamVeraSans-Roman-44\"/>\n",
       "     <use x=\"77.001953125\" xlink:href=\"#BitstreamVeraSans-Roman-65\"/>\n",
       "     <use x=\"138.525390625\" xlink:href=\"#BitstreamVeraSans-Roman-62\"/>\n",
       "     <use x=\"202.001953125\" xlink:href=\"#BitstreamVeraSans-Roman-62\"/>\n",
       "     <use x=\"265.478515625\" xlink:href=\"#BitstreamVeraSans-Roman-69\"/>\n",
       "     <use x=\"293.26171875\" xlink:href=\"#BitstreamVeraSans-Roman-65\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"text_3\">\n",
       "    <!-- Bob -->\n",
       "    <defs>\n",
       "     <path d=\"M 19.671875 34.8125 \n",
       "L 19.671875 8.109375 \n",
       "L 35.5 8.109375 \n",
       "Q 43.453125 8.109375 47.28125 11.40625 \n",
       "Q 51.125 14.703125 51.125 21.484375 \n",
       "Q 51.125 28.328125 47.28125 31.5625 \n",
       "Q 43.453125 34.8125 35.5 34.8125 \n",
       "z\n",
       "M 19.671875 64.796875 \n",
       "L 19.671875 42.828125 \n",
       "L 34.28125 42.828125 \n",
       "Q 41.5 42.828125 45.03125 45.53125 \n",
       "Q 48.578125 48.25 48.578125 53.8125 \n",
       "Q 48.578125 59.328125 45.03125 62.0625 \n",
       "Q 41.5 64.796875 34.28125 64.796875 \n",
       "z\n",
       "M 9.8125 72.90625 \n",
       "L 35.015625 72.90625 \n",
       "Q 46.296875 72.90625 52.390625 68.21875 \n",
       "Q 58.5 63.53125 58.5 54.890625 \n",
       "Q 58.5 48.1875 55.375 44.234375 \n",
       "Q 52.25 40.28125 46.1875 39.3125 \n",
       "Q 53.46875 37.75 57.5 32.78125 \n",
       "Q 61.53125 27.828125 61.53125 20.40625 \n",
       "Q 61.53125 10.640625 54.890625 5.3125 \n",
       "Q 48.25 0 35.984375 0 \n",
       "L 9.8125 0 \n",
       "z\n",
       "\" id=\"BitstreamVeraSans-Roman-42\"/>\n",
       "     <path d=\"M 30.609375 48.390625 \n",
       "Q 23.390625 48.390625 19.1875 42.75 \n",
       "Q 14.984375 37.109375 14.984375 27.296875 \n",
       "Q 14.984375 17.484375 19.15625 11.84375 \n",
       "Q 23.34375 6.203125 30.609375 6.203125 \n",
       "Q 37.796875 6.203125 41.984375 11.859375 \n",
       "Q 46.1875 17.53125 46.1875 27.296875 \n",
       "Q 46.1875 37.015625 41.984375 42.703125 \n",
       "Q 37.796875 48.390625 30.609375 48.390625 \n",
       "M 30.609375 56 \n",
       "Q 42.328125 56 49.015625 48.375 \n",
       "Q 55.71875 40.765625 55.71875 27.296875 \n",
       "Q 55.71875 13.875 49.015625 6.21875 \n",
       "Q 42.328125 -1.421875 30.609375 -1.421875 \n",
       "Q 18.84375 -1.421875 12.171875 6.21875 \n",
       "Q 5.515625 13.875 5.515625 27.296875 \n",
       "Q 5.515625 40.765625 12.171875 48.375 \n",
       "Q 18.84375 56 30.609375 56 \n",
       "\" id=\"BitstreamVeraSans-Roman-6f\"/>\n",
       "    </defs>\n",
       "    <g transform=\"translate(84.5081200787 66.1004133858)scale(0.08 -0.08)\">\n",
       "     <use xlink:href=\"#BitstreamVeraSans-Roman-42\"/>\n",
       "     <use x=\"68.603515625\" xlink:href=\"#BitstreamVeraSans-Roman-6f\"/>\n",
       "     <use x=\"129.78515625\" xlink:href=\"#BitstreamVeraSans-Roman-62\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"text_4\">\n",
       "    <!-- Charles -->\n",
       "    <defs>\n",
       "     <path d=\"M 34.28125 27.484375 \n",
       "Q 23.390625 27.484375 19.1875 25 \n",
       "Q 14.984375 22.515625 14.984375 16.5 \n",
       "Q 14.984375 11.71875 18.140625 8.90625 \n",
       "Q 21.296875 6.109375 26.703125 6.109375 \n",
       "Q 34.1875 6.109375 38.703125 11.40625 \n",
       "Q 43.21875 16.703125 43.21875 25.484375 \n",
       "L 43.21875 27.484375 \n",
       "z\n",
       "M 52.203125 31.203125 \n",
       "L 52.203125 0 \n",
       "L 43.21875 0 \n",
       "L 43.21875 8.296875 \n",
       "Q 40.140625 3.328125 35.546875 0.953125 \n",
       "Q 30.953125 -1.421875 24.3125 -1.421875 \n",
       "Q 15.921875 -1.421875 10.953125 3.296875 \n",
       "Q 6 8.015625 6 15.921875 \n",
       "Q 6 25.140625 12.171875 29.828125 \n",
       "Q 18.359375 34.515625 30.609375 34.515625 \n",
       "L 43.21875 34.515625 \n",
       "L 43.21875 35.40625 \n",
       "Q 43.21875 41.609375 39.140625 45 \n",
       "Q 35.0625 48.390625 27.6875 48.390625 \n",
       "Q 23 48.390625 18.546875 47.265625 \n",
       "Q 14.109375 46.140625 10.015625 43.890625 \n",
       "L 10.015625 52.203125 \n",
       "Q 14.9375 54.109375 19.578125 55.046875 \n",
       "Q 24.21875 56 28.609375 56 \n",
       "Q 40.484375 56 46.34375 49.84375 \n",
       "Q 52.203125 43.703125 52.203125 31.203125 \n",
       "\" id=\"BitstreamVeraSans-Roman-61\"/>\n",
       "     <path d=\"M 44.28125 53.078125 \n",
       "L 44.28125 44.578125 \n",
       "Q 40.484375 46.53125 36.375 47.5 \n",
       "Q 32.28125 48.484375 27.875 48.484375 \n",
       "Q 21.1875 48.484375 17.84375 46.4375 \n",
       "Q 14.5 44.390625 14.5 40.28125 \n",
       "Q 14.5 37.15625 16.890625 35.375 \n",
       "Q 19.28125 33.59375 26.515625 31.984375 \n",
       "L 29.59375 31.296875 \n",
       "Q 39.15625 29.25 43.1875 25.515625 \n",
       "Q 47.21875 21.78125 47.21875 15.09375 \n",
       "Q 47.21875 7.46875 41.1875 3.015625 \n",
       "Q 35.15625 -1.421875 24.609375 -1.421875 \n",
       "Q 20.21875 -1.421875 15.453125 -0.5625 \n",
       "Q 10.6875 0.296875 5.421875 2 \n",
       "L 5.421875 11.28125 \n",
       "Q 10.40625 8.6875 15.234375 7.390625 \n",
       "Q 20.0625 6.109375 24.8125 6.109375 \n",
       "Q 31.15625 6.109375 34.5625 8.28125 \n",
       "Q 37.984375 10.453125 37.984375 14.40625 \n",
       "Q 37.984375 18.0625 35.515625 20.015625 \n",
       "Q 33.0625 21.96875 24.703125 23.78125 \n",
       "L 21.578125 24.515625 \n",
       "Q 13.234375 26.265625 9.515625 29.90625 \n",
       "Q 5.8125 33.546875 5.8125 39.890625 \n",
       "Q 5.8125 47.609375 11.28125 51.796875 \n",
       "Q 16.75 56 26.8125 56 \n",
       "Q 31.78125 56 36.171875 55.265625 \n",
       "Q 40.578125 54.546875 44.28125 53.078125 \n",
       "\" id=\"BitstreamVeraSans-Roman-73\"/>\n",
       "     <path d=\"M 64.40625 67.28125 \n",
       "L 64.40625 56.890625 \n",
       "Q 59.421875 61.53125 53.78125 63.8125 \n",
       "Q 48.140625 66.109375 41.796875 66.109375 \n",
       "Q 29.296875 66.109375 22.65625 58.46875 \n",
       "Q 16.015625 50.828125 16.015625 36.375 \n",
       "Q 16.015625 21.96875 22.65625 14.328125 \n",
       "Q 29.296875 6.6875 41.796875 6.6875 \n",
       "Q 48.140625 6.6875 53.78125 8.984375 \n",
       "Q 59.421875 11.28125 64.40625 15.921875 \n",
       "L 64.40625 5.609375 \n",
       "Q 59.234375 2.09375 53.4375 0.328125 \n",
       "Q 47.65625 -1.421875 41.21875 -1.421875 \n",
       "Q 24.65625 -1.421875 15.125 8.703125 \n",
       "Q 5.609375 18.84375 5.609375 36.375 \n",
       "Q 5.609375 53.953125 15.125 64.078125 \n",
       "Q 24.65625 74.21875 41.21875 74.21875 \n",
       "Q 47.75 74.21875 53.53125 72.484375 \n",
       "Q 59.328125 70.75 64.40625 67.28125 \n",
       "\" id=\"BitstreamVeraSans-Roman-43\"/>\n",
       "     <path d=\"M 54.890625 33.015625 \n",
       "L 54.890625 0 \n",
       "L 45.90625 0 \n",
       "L 45.90625 32.71875 \n",
       "Q 45.90625 40.484375 42.875 44.328125 \n",
       "Q 39.84375 48.1875 33.796875 48.1875 \n",
       "Q 26.515625 48.1875 22.3125 43.546875 \n",
       "Q 18.109375 38.921875 18.109375 30.90625 \n",
       "L 18.109375 0 \n",
       "L 9.078125 0 \n",
       "L 9.078125 75.984375 \n",
       "L 18.109375 75.984375 \n",
       "L 18.109375 46.1875 \n",
       "Q 21.34375 51.125 25.703125 53.5625 \n",
       "Q 30.078125 56 35.796875 56 \n",
       "Q 45.21875 56 50.046875 50.171875 \n",
       "Q 54.890625 44.34375 54.890625 33.015625 \n",
       "\" id=\"BitstreamVeraSans-Roman-68\"/>\n",
       "     <path d=\"M 41.109375 46.296875 \n",
       "Q 39.59375 47.171875 37.8125 47.578125 \n",
       "Q 36.03125 48 33.890625 48 \n",
       "Q 26.265625 48 22.1875 43.046875 \n",
       "Q 18.109375 38.09375 18.109375 28.8125 \n",
       "L 18.109375 0 \n",
       "L 9.078125 0 \n",
       "L 9.078125 54.6875 \n",
       "L 18.109375 54.6875 \n",
       "L 18.109375 46.1875 \n",
       "Q 20.953125 51.171875 25.484375 53.578125 \n",
       "Q 30.03125 56 36.53125 56 \n",
       "Q 37.453125 56 38.578125 55.875 \n",
       "Q 39.703125 55.765625 41.0625 55.515625 \n",
       "z\n",
       "\" id=\"BitstreamVeraSans-Roman-72\"/>\n",
       "    </defs>\n",
       "    <g transform=\"translate(48.8129133858 94.4468700787)scale(0.08 -0.08)\">\n",
       "     <use xlink:href=\"#BitstreamVeraSans-Roman-43\"/>\n",
       "     <use x=\"69.82421875\" xlink:href=\"#BitstreamVeraSans-Roman-68\"/>\n",
       "     <use x=\"133.203125\" xlink:href=\"#BitstreamVeraSans-Roman-61\"/>\n",
       "     <use x=\"194.482421875\" xlink:href=\"#BitstreamVeraSans-Roman-72\"/>\n",
       "     <use x=\"235.595703125\" xlink:href=\"#BitstreamVeraSans-Roman-6c\"/>\n",
       "     <use x=\"263.37890625\" xlink:href=\"#BitstreamVeraSans-Roman-65\"/>\n",
       "     <use x=\"324.90234375\" xlink:href=\"#BitstreamVeraSans-Roman-73\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "  </g>\n",
       " </g>\n",
       " <defs>\n",
       "  <clipPath id=\"pc2bb445a41\">\n",
       "   <rect height=\"113.385826772\" width=\"113.385826772\" x=\"7.2\" y=\"7.2\"/>\n",
       "  </clipPath>\n",
       " </defs>\n",
       "</svg>\n"
      ],
      "text/plain": [
       "<matplotlib.figure.Figure at 0x7feb96d72128>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "pgm = daft.PGM([2, 2], origin=[-0.5, 0.5], directed=False)\n",
    "add_node(pgm, 'a', 'Alice', 0.5, 2, label_params={'size':8})\n",
    "add_node(pgm, 'b', 'Bob', 1, 1.5, label_params={'size':8})\n",
    "add_node(pgm, 'c', 'Charles', 0.5, 1, label_params={'size':8})\n",
    "add_node(pgm, 'd', 'Debbie', 0, 1.5, label_params={'size':8})\n",
    "add_edges(pgm, [\n",
    "        ('a', 'b'),\n",
    "        ('d', 'a'),\n",
    "        ('b', 'c'),\n",
    "        ('c', 'd')\n",
    "    ])\n",
    "pgm.render()\n",
    "save('markov_network_00')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 53,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "image/svg+xml": [
       "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"no\"?>\n",
       "<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\n",
       "  \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n",
       "<!-- Created with matplotlib (http://matplotlib.org/) -->\n",
       "<svg height=\"127pt\" version=\"1.1\" viewBox=\"0 0 127 127\" width=\"127pt\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n",
       " <defs>\n",
       "  <style type=\"text/css\">\n",
       "*{stroke-linecap:butt;stroke-linejoin:round;stroke-miterlimit:100000;}\n",
       "  </style>\n",
       " </defs>\n",
       " <g id=\"figure_1\">\n",
       "  <g id=\"patch_1\">\n",
       "   <path d=\"M 0 127.785827 \n",
       "L 127.785827 127.785827 \n",
       "L 127.785827 0 \n",
       "L 0 0 \n",
       "L 0 127.785827 \n",
       "z\n",
       "\" style=\"fill:none;\"/>\n",
       "  </g>\n",
       "  <g id=\"axes_1\">\n",
       "   <g id=\"patch_2\">\n",
       "    <path clip-path=\"url(#pe929247ff7)\" d=\"M 63.892913 52.554331 \n",
       "C 68.403454 52.554331 72.729862 50.762274 75.919296 47.57284 \n",
       "C 79.108731 44.383406 80.900787 40.056998 80.900787 35.546457 \n",
       "C 80.900787 31.035916 79.108731 26.709508 75.919296 23.520074 \n",
       "C 72.729862 20.33064 68.403454 18.538583 63.892913 18.538583 \n",
       "C 59.382372 18.538583 55.055964 20.33064 51.86653 23.520074 \n",
       "C 48.677096 26.709508 46.885039 31.035916 46.885039 35.546457 \n",
       "C 46.885039 40.056998 48.677096 44.383406 51.86653 47.57284 \n",
       "C 55.055964 50.762274 59.382372 52.554331 63.892913 52.554331 \n",
       "L 63.892913 52.554331 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_3\">\n",
       "    <path clip-path=\"url(#pe929247ff7)\" d=\"M 35.546457 80.900787 \n",
       "C 40.056998 80.900787 44.383406 79.108731 47.57284 75.919296 \n",
       "C 50.762274 72.729862 52.554331 68.403454 52.554331 63.892913 \n",
       "C 52.554331 59.382372 50.762274 55.055964 47.57284 51.86653 \n",
       "C 44.383406 48.677096 40.056998 46.885039 35.546457 46.885039 \n",
       "C 31.035916 46.885039 26.709508 48.677096 23.520074 51.86653 \n",
       "C 20.33064 55.055964 18.538583 59.382372 18.538583 63.892913 \n",
       "C 18.538583 68.403454 20.33064 72.729862 23.520074 75.919296 \n",
       "C 26.709508 79.108731 31.035916 80.900787 35.546457 80.900787 \n",
       "L 35.546457 80.900787 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_4\">\n",
       "    <path clip-path=\"url(#pe929247ff7)\" d=\"M 92.23937 80.900787 \n",
       "C 96.749911 80.900787 101.076319 79.108731 104.265753 75.919296 \n",
       "C 107.455187 72.729862 109.247244 68.403454 109.247244 63.892913 \n",
       "C 109.247244 59.382372 107.455187 55.055964 104.265753 51.86653 \n",
       "C 101.076319 48.677096 96.749911 46.885039 92.23937 46.885039 \n",
       "C 87.728829 46.885039 83.402421 48.677096 80.212987 51.86653 \n",
       "C 77.023553 55.055964 75.231496 59.382372 75.231496 63.892913 \n",
       "C 75.231496 68.403454 77.023553 72.729862 80.212987 75.919296 \n",
       "C 83.402421 79.108731 87.728829 80.900787 92.23937 80.900787 \n",
       "L 92.23937 80.900787 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_5\">\n",
       "    <path clip-path=\"url(#pe929247ff7)\" d=\"M 63.892913 109.247244 \n",
       "C 68.403454 109.247244 72.729862 107.455187 75.919296 104.265753 \n",
       "C 79.108731 101.076319 80.900787 96.749911 80.900787 92.23937 \n",
       "C 80.900787 87.728829 79.108731 83.402421 75.919296 80.212987 \n",
       "C 72.729862 77.023553 68.403454 75.231496 63.892913 75.231496 \n",
       "C 59.382372 75.231496 55.055964 77.023553 51.86653 80.212987 \n",
       "C 48.677096 83.402421 46.885039 87.728829 46.885039 92.23937 \n",
       "C 46.885039 96.749911 48.677096 101.076319 51.86653 104.265753 \n",
       "C 55.055964 107.455187 59.382372 109.247244 63.892913 109.247244 \n",
       "L 63.892913 109.247244 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"line2d_1\">\n",
       "    <path clip-path=\"url(#pe929247ff7)\" d=\"M 75.919296 47.57284 \n",
       "L 80.212987 51.86653 \n",
       "\" style=\"fill:none;stroke:#000000;stroke-linecap:square;\"/>\n",
       "   </g>\n",
       "   <g id=\"line2d_2\">\n",
       "    <path clip-path=\"url(#pe929247ff7)\" d=\"M 47.57284 51.86653 \n",
       "L 51.86653 47.57284 \n",
       "\" style=\"fill:none;stroke:#000000;stroke-linecap:square;\"/>\n",
       "   </g>\n",
       "   <g id=\"line2d_3\">\n",
       "    <path clip-path=\"url(#pe929247ff7)\" d=\"M 80.212987 75.919296 \n",
       "L 75.919296 80.212987 \n",
       "\" style=\"fill:none;stroke:#000000;stroke-linecap:square;\"/>\n",
       "   </g>\n",
       "   <g id=\"line2d_4\">\n",
       "    <path clip-path=\"url(#pe929247ff7)\" d=\"M 51.86653 80.212987 \n",
       "L 47.57284 75.919296 \n",
       "\" style=\"fill:none;stroke:#000000;stroke-linecap:square;\"/>\n",
       "   </g>\n",
       "   <g id=\"matplotlib.axis_1\"/>\n",
       "   <g id=\"matplotlib.axis_2\"/>\n",
       "   <g id=\"text_1\">\n",
       "    <!-- A -->\n",
       "    <defs>\n",
       "     <path d=\"M 34.1875 63.1875 \n",
       "L 20.796875 26.90625 \n",
       "L 47.609375 26.90625 \n",
       "z\n",
       "M 28.609375 72.90625 \n",
       "L 39.796875 72.90625 \n",
       "L 67.578125 0 \n",
       "L 57.328125 0 \n",
       "L 50.6875 18.703125 \n",
       "L 17.828125 18.703125 \n",
       "L 11.1875 0 \n",
       "L 0.78125 0 \n",
       "z\n",
       "\" id=\"BitstreamVeraSans-Roman-41\"/>\n",
       "    </defs>\n",
       "    <g transform=\"translate(57.7363508858 40.5133316929)scale(0.18 -0.18)\">\n",
       "     <use xlink:href=\"#BitstreamVeraSans-Roman-41\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"text_2\">\n",
       "    <!-- D -->\n",
       "    <defs>\n",
       "     <path d=\"M 19.671875 64.796875 \n",
       "L 19.671875 8.109375 \n",
       "L 31.59375 8.109375 \n",
       "Q 46.6875 8.109375 53.6875 14.9375 \n",
       "Q 60.6875 21.78125 60.6875 36.53125 \n",
       "Q 60.6875 51.171875 53.6875 57.984375 \n",
       "Q 46.6875 64.796875 31.59375 64.796875 \n",
       "z\n",
       "M 9.8125 72.90625 \n",
       "L 30.078125 72.90625 \n",
       "Q 51.265625 72.90625 61.171875 64.09375 \n",
       "Q 71.09375 55.28125 71.09375 36.53125 \n",
       "Q 71.09375 17.671875 61.125 8.828125 \n",
       "Q 51.171875 0 30.078125 0 \n",
       "L 9.8125 0 \n",
       "z\n",
       "\" id=\"BitstreamVeraSans-Roman-44\"/>\n",
       "    </defs>\n",
       "    <g transform=\"translate(28.6164566929 68.8597883858)scale(0.18 -0.18)\">\n",
       "     <use xlink:href=\"#BitstreamVeraSans-Roman-44\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"text_3\">\n",
       "    <!-- B -->\n",
       "    <defs>\n",
       "     <path d=\"M 19.671875 34.8125 \n",
       "L 19.671875 8.109375 \n",
       "L 35.5 8.109375 \n",
       "Q 43.453125 8.109375 47.28125 11.40625 \n",
       "Q 51.125 14.703125 51.125 21.484375 \n",
       "Q 51.125 28.328125 47.28125 31.5625 \n",
       "Q 43.453125 34.8125 35.5 34.8125 \n",
       "z\n",
       "M 19.671875 64.796875 \n",
       "L 19.671875 42.828125 \n",
       "L 34.28125 42.828125 \n",
       "Q 41.5 42.828125 45.03125 45.53125 \n",
       "Q 48.578125 48.25 48.578125 53.8125 \n",
       "Q 48.578125 59.328125 45.03125 62.0625 \n",
       "Q 41.5 64.796875 34.28125 64.796875 \n",
       "z\n",
       "M 9.8125 72.90625 \n",
       "L 35.015625 72.90625 \n",
       "Q 46.296875 72.90625 52.390625 68.21875 \n",
       "Q 58.5 63.53125 58.5 54.890625 \n",
       "Q 58.5 48.1875 55.375 44.234375 \n",
       "Q 52.25 40.28125 46.1875 39.3125 \n",
       "Q 53.46875 37.75 57.5 32.78125 \n",
       "Q 61.53125 27.828125 61.53125 20.40625 \n",
       "Q 61.53125 10.640625 54.890625 5.3125 \n",
       "Q 48.25 0 35.984375 0 \n",
       "L 9.8125 0 \n",
       "z\n",
       "\" id=\"BitstreamVeraSans-Roman-42\"/>\n",
       "    </defs>\n",
       "    <g transform=\"translate(86.0645263287 68.8597883858)scale(0.18 -0.18)\">\n",
       "     <use xlink:href=\"#BitstreamVeraSans-Roman-42\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"text_4\">\n",
       "    <!-- C -->\n",
       "    <defs>\n",
       "     <path d=\"M 64.40625 67.28125 \n",
       "L 64.40625 56.890625 \n",
       "Q 59.421875 61.53125 53.78125 63.8125 \n",
       "Q 48.140625 66.109375 41.796875 66.109375 \n",
       "Q 29.296875 66.109375 22.65625 58.46875 \n",
       "Q 16.015625 50.828125 16.015625 36.375 \n",
       "Q 16.015625 21.96875 22.65625 14.328125 \n",
       "Q 29.296875 6.6875 41.796875 6.6875 \n",
       "Q 48.140625 6.6875 53.78125 8.984375 \n",
       "Q 59.421875 11.28125 64.40625 15.921875 \n",
       "L 64.40625 5.609375 \n",
       "Q 59.234375 2.09375 53.4375 0.328125 \n",
       "Q 47.65625 -1.421875 41.21875 -1.421875 \n",
       "Q 24.65625 -1.421875 15.125 8.703125 \n",
       "Q 5.609375 18.84375 5.609375 36.375 \n",
       "Q 5.609375 53.953125 15.125 64.078125 \n",
       "Q 24.65625 74.21875 41.21875 74.21875 \n",
       "Q 47.75 74.21875 53.53125 72.484375 \n",
       "Q 59.328125 70.75 64.40625 67.28125 \n",
       "\" id=\"BitstreamVeraSans-Roman-43\"/>\n",
       "    </defs>\n",
       "    <g transform=\"translate(57.6083821358 97.2062450787)scale(0.18 -0.18)\">\n",
       "     <use xlink:href=\"#BitstreamVeraSans-Roman-43\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "  </g>\n",
       " </g>\n",
       " <defs>\n",
       "  <clipPath id=\"pe929247ff7\">\n",
       "   <rect height=\"113.385826772\" width=\"113.385826772\" x=\"7.2\" y=\"7.2\"/>\n",
       "  </clipPath>\n",
       " </defs>\n",
       "</svg>\n"
      ],
      "text/plain": [
       "<matplotlib.figure.Figure at 0x7feb9a0a8fd0>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "pgm = daft.PGM([2, 2], origin=[-0.5, 0.5], directed=False)\n",
    "add_node(pgm, 'a', 'A', 0.5, 2)\n",
    "add_node(pgm, 'b', 'B', 1, 1.5)\n",
    "add_node(pgm, 'c', 'C', 0.5, 1)\n",
    "add_node(pgm, 'd', 'D', 0, 1.5)\n",
    "add_edges(pgm, [\n",
    "        ('a', 'b'),\n",
    "        ('d', 'a'),\n",
    "        ('b', 'c'),\n",
    "        ('c', 'd')\n",
    "    ])\n",
    "pgm.render()\n",
    "save('markov_network_01')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 54,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "image/svg+xml": [
       "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"no\"?>\n",
       "<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\n",
       "  \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n",
       "<!-- Created with matplotlib (http://matplotlib.org/) -->\n",
       "<svg height=\"127pt\" version=\"1.1\" viewBox=\"0 0 127 127\" width=\"127pt\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n",
       " <defs>\n",
       "  <style type=\"text/css\">\n",
       "*{stroke-linecap:butt;stroke-linejoin:round;stroke-miterlimit:100000;}\n",
       "  </style>\n",
       " </defs>\n",
       " <g id=\"figure_1\">\n",
       "  <g id=\"patch_1\">\n",
       "   <path d=\"M 0 127.785827 \n",
       "L 127.785827 127.785827 \n",
       "L 127.785827 0 \n",
       "L 0 0 \n",
       "L 0 127.785827 \n",
       "z\n",
       "\" style=\"fill:none;\"/>\n",
       "  </g>\n",
       "  <g id=\"axes_1\">\n",
       "   <g id=\"patch_2\">\n",
       "    <path clip-path=\"url(#pa37a834f0d)\" d=\"M 63.892913 52.554331 \n",
       "C 68.403454 52.554331 72.729862 50.762274 75.919296 47.57284 \n",
       "C 79.108731 44.383406 80.900787 40.056998 80.900787 35.546457 \n",
       "C 80.900787 31.035916 79.108731 26.709508 75.919296 23.520074 \n",
       "C 72.729862 20.33064 68.403454 18.538583 63.892913 18.538583 \n",
       "C 59.382372 18.538583 55.055964 20.33064 51.86653 23.520074 \n",
       "C 48.677096 26.709508 46.885039 31.035916 46.885039 35.546457 \n",
       "C 46.885039 40.056998 48.677096 44.383406 51.86653 47.57284 \n",
       "C 55.055964 50.762274 59.382372 52.554331 63.892913 52.554331 \n",
       "L 63.892913 52.554331 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_3\">\n",
       "    <path clip-path=\"url(#pa37a834f0d)\" d=\"M 35.546457 80.900787 \n",
       "C 40.056998 80.900787 44.383406 79.108731 47.57284 75.919296 \n",
       "C 50.762274 72.729862 52.554331 68.403454 52.554331 63.892913 \n",
       "C 52.554331 59.382372 50.762274 55.055964 47.57284 51.86653 \n",
       "C 44.383406 48.677096 40.056998 46.885039 35.546457 46.885039 \n",
       "C 31.035916 46.885039 26.709508 48.677096 23.520074 51.86653 \n",
       "C 20.33064 55.055964 18.538583 59.382372 18.538583 63.892913 \n",
       "C 18.538583 68.403454 20.33064 72.729862 23.520074 75.919296 \n",
       "C 26.709508 79.108731 31.035916 80.900787 35.546457 80.900787 \n",
       "L 35.546457 80.900787 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_4\">\n",
       "    <path clip-path=\"url(#pa37a834f0d)\" d=\"M 92.23937 80.900787 \n",
       "C 96.749911 80.900787 101.076319 79.108731 104.265753 75.919296 \n",
       "C 107.455187 72.729862 109.247244 68.403454 109.247244 63.892913 \n",
       "C 109.247244 59.382372 107.455187 55.055964 104.265753 51.86653 \n",
       "C 101.076319 48.677096 96.749911 46.885039 92.23937 46.885039 \n",
       "C 87.728829 46.885039 83.402421 48.677096 80.212987 51.86653 \n",
       "C 77.023553 55.055964 75.231496 59.382372 75.231496 63.892913 \n",
       "C 75.231496 68.403454 77.023553 72.729862 80.212987 75.919296 \n",
       "C 83.402421 79.108731 87.728829 80.900787 92.23937 80.900787 \n",
       "L 92.23937 80.900787 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_5\">\n",
       "    <path clip-path=\"url(#pa37a834f0d)\" d=\"M 63.892913 109.247244 \n",
       "C 68.403454 109.247244 72.729862 107.455187 75.919296 104.265753 \n",
       "C 79.108731 101.076319 80.900787 96.749911 80.900787 92.23937 \n",
       "C 80.900787 87.728829 79.108731 83.402421 75.919296 80.212987 \n",
       "C 72.729862 77.023553 68.403454 75.231496 63.892913 75.231496 \n",
       "C 59.382372 75.231496 55.055964 77.023553 51.86653 80.212987 \n",
       "C 48.677096 83.402421 46.885039 87.728829 46.885039 92.23937 \n",
       "C 46.885039 96.749911 48.677096 101.076319 51.86653 104.265753 \n",
       "C 55.055964 107.455187 59.382372 109.247244 63.892913 109.247244 \n",
       "L 63.892913 109.247244 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"line2d_1\">\n",
       "    <path clip-path=\"url(#pa37a834f0d)\" d=\"M 75.919296 47.57284 \n",
       "L 80.212987 51.86653 \n",
       "\" style=\"fill:none;stroke:#000000;stroke-linecap:square;\"/>\n",
       "   </g>\n",
       "   <g id=\"line2d_2\">\n",
       "    <path clip-path=\"url(#pa37a834f0d)\" d=\"M 80.212987 75.919296 \n",
       "L 75.919296 80.212987 \n",
       "\" style=\"fill:none;stroke:#000000;stroke-linecap:square;\"/>\n",
       "   </g>\n",
       "   <g id=\"line2d_3\">\n",
       "    <path clip-path=\"url(#pa37a834f0d)\" d=\"M 51.86653 80.212987 \n",
       "L 47.57284 75.919296 \n",
       "\" style=\"fill:none;stroke:#000000;stroke-linecap:square;\"/>\n",
       "   </g>\n",
       "   <g id=\"line2d_4\">\n",
       "    <path clip-path=\"url(#pa37a834f0d)\" d=\"M 75.231496 63.892913 \n",
       "L 52.554331 63.892913 \n",
       "\" style=\"fill:none;stroke:#000000;stroke-linecap:square;\"/>\n",
       "   </g>\n",
       "   <g id=\"line2d_5\">\n",
       "    <path clip-path=\"url(#pa37a834f0d)\" d=\"M 63.892913 52.554331 \n",
       "L 63.892913 75.231496 \n",
       "\" style=\"fill:none;stroke:#000000;stroke-linecap:square;\"/>\n",
       "   </g>\n",
       "   <g id=\"matplotlib.axis_1\"/>\n",
       "   <g id=\"matplotlib.axis_2\"/>\n",
       "   <g id=\"text_1\">\n",
       "    <!-- A -->\n",
       "    <defs>\n",
       "     <path d=\"M 34.1875 63.1875 \n",
       "L 20.796875 26.90625 \n",
       "L 47.609375 26.90625 \n",
       "z\n",
       "M 28.609375 72.90625 \n",
       "L 39.796875 72.90625 \n",
       "L 67.578125 0 \n",
       "L 57.328125 0 \n",
       "L 50.6875 18.703125 \n",
       "L 17.828125 18.703125 \n",
       "L 11.1875 0 \n",
       "L 0.78125 0 \n",
       "z\n",
       "\" id=\"BitstreamVeraSans-Roman-41\"/>\n",
       "    </defs>\n",
       "    <g transform=\"translate(57.7363508858 40.5133316929)scale(0.18 -0.18)\">\n",
       "     <use xlink:href=\"#BitstreamVeraSans-Roman-41\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"text_2\">\n",
       "    <!-- D -->\n",
       "    <defs>\n",
       "     <path d=\"M 19.671875 64.796875 \n",
       "L 19.671875 8.109375 \n",
       "L 31.59375 8.109375 \n",
       "Q 46.6875 8.109375 53.6875 14.9375 \n",
       "Q 60.6875 21.78125 60.6875 36.53125 \n",
       "Q 60.6875 51.171875 53.6875 57.984375 \n",
       "Q 46.6875 64.796875 31.59375 64.796875 \n",
       "z\n",
       "M 9.8125 72.90625 \n",
       "L 30.078125 72.90625 \n",
       "Q 51.265625 72.90625 61.171875 64.09375 \n",
       "Q 71.09375 55.28125 71.09375 36.53125 \n",
       "Q 71.09375 17.671875 61.125 8.828125 \n",
       "Q 51.171875 0 30.078125 0 \n",
       "L 9.8125 0 \n",
       "z\n",
       "\" id=\"BitstreamVeraSans-Roman-44\"/>\n",
       "    </defs>\n",
       "    <g transform=\"translate(28.6164566929 68.8597883858)scale(0.18 -0.18)\">\n",
       "     <use xlink:href=\"#BitstreamVeraSans-Roman-44\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"text_3\">\n",
       "    <!-- B -->\n",
       "    <defs>\n",
       "     <path d=\"M 19.671875 34.8125 \n",
       "L 19.671875 8.109375 \n",
       "L 35.5 8.109375 \n",
       "Q 43.453125 8.109375 47.28125 11.40625 \n",
       "Q 51.125 14.703125 51.125 21.484375 \n",
       "Q 51.125 28.328125 47.28125 31.5625 \n",
       "Q 43.453125 34.8125 35.5 34.8125 \n",
       "z\n",
       "M 19.671875 64.796875 \n",
       "L 19.671875 42.828125 \n",
       "L 34.28125 42.828125 \n",
       "Q 41.5 42.828125 45.03125 45.53125 \n",
       "Q 48.578125 48.25 48.578125 53.8125 \n",
       "Q 48.578125 59.328125 45.03125 62.0625 \n",
       "Q 41.5 64.796875 34.28125 64.796875 \n",
       "z\n",
       "M 9.8125 72.90625 \n",
       "L 35.015625 72.90625 \n",
       "Q 46.296875 72.90625 52.390625 68.21875 \n",
       "Q 58.5 63.53125 58.5 54.890625 \n",
       "Q 58.5 48.1875 55.375 44.234375 \n",
       "Q 52.25 40.28125 46.1875 39.3125 \n",
       "Q 53.46875 37.75 57.5 32.78125 \n",
       "Q 61.53125 27.828125 61.53125 20.40625 \n",
       "Q 61.53125 10.640625 54.890625 5.3125 \n",
       "Q 48.25 0 35.984375 0 \n",
       "L 9.8125 0 \n",
       "z\n",
       "\" id=\"BitstreamVeraSans-Roman-42\"/>\n",
       "    </defs>\n",
       "    <g transform=\"translate(86.0645263287 68.8597883858)scale(0.18 -0.18)\">\n",
       "     <use xlink:href=\"#BitstreamVeraSans-Roman-42\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"text_4\">\n",
       "    <!-- C -->\n",
       "    <defs>\n",
       "     <path d=\"M 64.40625 67.28125 \n",
       "L 64.40625 56.890625 \n",
       "Q 59.421875 61.53125 53.78125 63.8125 \n",
       "Q 48.140625 66.109375 41.796875 66.109375 \n",
       "Q 29.296875 66.109375 22.65625 58.46875 \n",
       "Q 16.015625 50.828125 16.015625 36.375 \n",
       "Q 16.015625 21.96875 22.65625 14.328125 \n",
       "Q 29.296875 6.6875 41.796875 6.6875 \n",
       "Q 48.140625 6.6875 53.78125 8.984375 \n",
       "Q 59.421875 11.28125 64.40625 15.921875 \n",
       "L 64.40625 5.609375 \n",
       "Q 59.234375 2.09375 53.4375 0.328125 \n",
       "Q 47.65625 -1.421875 41.21875 -1.421875 \n",
       "Q 24.65625 -1.421875 15.125 8.703125 \n",
       "Q 5.609375 18.84375 5.609375 36.375 \n",
       "Q 5.609375 53.953125 15.125 64.078125 \n",
       "Q 24.65625 74.21875 41.21875 74.21875 \n",
       "Q 47.75 74.21875 53.53125 72.484375 \n",
       "Q 59.328125 70.75 64.40625 67.28125 \n",
       "\" id=\"BitstreamVeraSans-Roman-43\"/>\n",
       "    </defs>\n",
       "    <g transform=\"translate(57.6083821358 97.2062450787)scale(0.18 -0.18)\">\n",
       "     <use xlink:href=\"#BitstreamVeraSans-Roman-43\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "  </g>\n",
       " </g>\n",
       " <defs>\n",
       "  <clipPath id=\"pa37a834f0d\">\n",
       "   <rect height=\"113.385826772\" width=\"113.385826772\" x=\"7.2\" y=\"7.2\"/>\n",
       "  </clipPath>\n",
       " </defs>\n",
       "</svg>\n"
      ],
      "text/plain": [
       "<matplotlib.figure.Figure at 0x7feb96e49470>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "pgm = daft.PGM([2, 2], origin=[-0.5, 0.5], directed=False)\n",
    "add_node(pgm, 'a', 'A', 0.5, 2)\n",
    "add_node(pgm, 'b', 'B', 1, 1.5)\n",
    "add_node(pgm, 'c', 'C', 0.5, 1)\n",
    "add_node(pgm, 'd', 'D', 0, 1.5)\n",
    "add_edges(pgm, [\n",
    "        ('a', 'b'),\n",
    "        ('b', 'c'),\n",
    "        ('c', 'd'),\n",
    "        ('b', 'd'),\n",
    "        ('a', 'c')\n",
    "    ])\n",
    "pgm.render()\n",
    "save('markov_network_induced')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 55,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "image/svg+xml": [
       "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"no\"?>\n",
       "<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\n",
       "  \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n",
       "<!-- Created with matplotlib (http://matplotlib.org/) -->\n",
       "<svg height=\"127pt\" version=\"1.1\" viewBox=\"0 0 184 127\" width=\"184pt\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n",
       " <defs>\n",
       "  <style type=\"text/css\">\n",
       "*{stroke-linecap:butt;stroke-linejoin:round;stroke-miterlimit:100000;}\n",
       "  </style>\n",
       " </defs>\n",
       " <g id=\"figure_1\">\n",
       "  <g id=\"patch_1\">\n",
       "   <path d=\"M 0 127.785827 \n",
       "L 184.47874 127.785827 \n",
       "L 184.47874 0 \n",
       "L 0 0 \n",
       "L 0 127.785827 \n",
       "z\n",
       "\" style=\"fill:none;\"/>\n",
       "  </g>\n",
       "  <g id=\"axes_1\">\n",
       "   <g id=\"patch_2\">\n",
       "    <path clip-path=\"url(#p2a9c33704d)\" d=\"M 63.892913 52.554331 \n",
       "C 68.403454 52.554331 72.729862 50.762274 75.919296 47.57284 \n",
       "C 79.108731 44.383406 80.900787 40.056998 80.900787 35.546457 \n",
       "C 80.900787 31.035916 79.108731 26.709508 75.919296 23.520074 \n",
       "C 72.729862 20.33064 68.403454 18.538583 63.892913 18.538583 \n",
       "C 59.382372 18.538583 55.055964 20.33064 51.86653 23.520074 \n",
       "C 48.677096 26.709508 46.885039 31.035916 46.885039 35.546457 \n",
       "C 46.885039 40.056998 48.677096 44.383406 51.86653 47.57284 \n",
       "C 55.055964 50.762274 59.382372 52.554331 63.892913 52.554331 \n",
       "L 63.892913 52.554331 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_3\">\n",
       "    <path clip-path=\"url(#p2a9c33704d)\" d=\"M 120.585827 52.554331 \n",
       "C 125.096368 52.554331 129.422776 50.762274 132.61221 47.57284 \n",
       "C 135.801644 44.383406 137.593701 40.056998 137.593701 35.546457 \n",
       "C 137.593701 31.035916 135.801644 26.709508 132.61221 23.520074 \n",
       "C 129.422776 20.33064 125.096368 18.538583 120.585827 18.538583 \n",
       "C 116.075286 18.538583 111.748878 20.33064 108.559444 23.520074 \n",
       "C 105.37001 26.709508 103.577953 31.035916 103.577953 35.546457 \n",
       "C 103.577953 40.056998 105.37001 44.383406 108.559444 47.57284 \n",
       "C 111.748878 50.762274 116.075286 52.554331 120.585827 52.554331 \n",
       "L 120.585827 52.554331 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_4\">\n",
       "    <path clip-path=\"url(#p2a9c33704d)\" d=\"M 63.892913 109.247244 \n",
       "C 68.403454 109.247244 72.729862 107.455187 75.919296 104.265753 \n",
       "C 79.108731 101.076319 80.900787 96.749911 80.900787 92.23937 \n",
       "C 80.900787 87.728829 79.108731 83.402421 75.919296 80.212987 \n",
       "C 72.729862 77.023553 68.403454 75.231496 63.892913 75.231496 \n",
       "C 59.382372 75.231496 55.055964 77.023553 51.86653 80.212987 \n",
       "C 48.677096 83.402421 46.885039 87.728829 46.885039 92.23937 \n",
       "C 46.885039 96.749911 48.677096 101.076319 51.86653 104.265753 \n",
       "C 55.055964 107.455187 59.382372 109.247244 63.892913 109.247244 \n",
       "L 63.892913 109.247244 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_5\">\n",
       "    <path clip-path=\"url(#p2a9c33704d)\" d=\"M 35.546457 80.900787 \n",
       "C 40.056998 80.900787 44.383406 79.108731 47.57284 75.919296 \n",
       "C 50.762274 72.729862 52.554331 68.403454 52.554331 63.892913 \n",
       "C 52.554331 59.382372 50.762274 55.055964 47.57284 51.86653 \n",
       "C 44.383406 48.677096 40.056998 46.885039 35.546457 46.885039 \n",
       "C 31.035916 46.885039 26.709508 48.677096 23.520074 51.86653 \n",
       "C 20.33064 55.055964 18.538583 59.382372 18.538583 63.892913 \n",
       "C 18.538583 68.403454 20.33064 72.729862 23.520074 75.919296 \n",
       "C 26.709508 79.108731 31.035916 80.900787 35.546457 80.900787 \n",
       "L 35.546457 80.900787 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_6\">\n",
       "    <path clip-path=\"url(#p2a9c33704d)\" d=\"M 92.23937 80.900787 \n",
       "C 96.749911 80.900787 101.076319 79.108731 104.265753 75.919296 \n",
       "C 107.455187 72.729862 109.247244 68.403454 109.247244 63.892913 \n",
       "C 109.247244 59.382372 107.455187 55.055964 104.265753 51.86653 \n",
       "C 101.076319 48.677096 96.749911 46.885039 92.23937 46.885039 \n",
       "C 87.728829 46.885039 83.402421 48.677096 80.212987 51.86653 \n",
       "C 77.023553 55.055964 75.231496 59.382372 75.231496 63.892913 \n",
       "C 75.231496 68.403454 77.023553 72.729862 80.212987 75.919296 \n",
       "C 83.402421 79.108731 87.728829 80.900787 92.23937 80.900787 \n",
       "L 92.23937 80.900787 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_7\">\n",
       "    <path clip-path=\"url(#p2a9c33704d)\" d=\"M 120.585827 109.247244 \n",
       "C 125.096368 109.247244 129.422776 107.455187 132.61221 104.265753 \n",
       "C 135.801644 101.076319 137.593701 96.749911 137.593701 92.23937 \n",
       "C 137.593701 87.728829 135.801644 83.402421 132.61221 80.212987 \n",
       "C 129.422776 77.023553 125.096368 75.231496 120.585827 75.231496 \n",
       "C 116.075286 75.231496 111.748878 77.023553 108.559444 80.212987 \n",
       "C 105.37001 83.402421 103.577953 87.728829 103.577953 92.23937 \n",
       "C 103.577953 96.749911 105.37001 101.076319 108.559444 104.265753 \n",
       "C 111.748878 107.455187 116.075286 109.247244 120.585827 109.247244 \n",
       "L 120.585827 109.247244 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"line2d_1\">\n",
       "    <path clip-path=\"url(#p2a9c33704d)\" d=\"M 47.57284 51.86653 \n",
       "L 51.86653 47.57284 \n",
       "\" style=\"fill:none;stroke:#000000;stroke-linecap:square;\"/>\n",
       "   </g>\n",
       "   <g id=\"line2d_2\">\n",
       "    <path clip-path=\"url(#p2a9c33704d)\" d=\"M 51.86653 80.212987 \n",
       "L 47.57284 75.919296 \n",
       "\" style=\"fill:none;stroke:#000000;stroke-linecap:square;\"/>\n",
       "   </g>\n",
       "   <g id=\"line2d_3\">\n",
       "    <path clip-path=\"url(#p2a9c33704d)\" d=\"M 75.231496 63.892913 \n",
       "L 52.554331 63.892913 \n",
       "\" style=\"fill:none;stroke:#000000;stroke-linecap:square;\"/>\n",
       "   </g>\n",
       "   <g id=\"line2d_4\">\n",
       "    <path clip-path=\"url(#p2a9c33704d)\" d=\"M 104.265753 51.86653 \n",
       "L 108.559444 47.57284 \n",
       "\" style=\"fill:none;stroke:#000000;stroke-linecap:square;\"/>\n",
       "   </g>\n",
       "   <g id=\"line2d_5\">\n",
       "    <path clip-path=\"url(#p2a9c33704d)\" d=\"M 104.265753 75.919296 \n",
       "L 108.559444 80.212987 \n",
       "\" style=\"fill:none;stroke:#000000;stroke-linecap:square;\"/>\n",
       "   </g>\n",
       "   <g id=\"line2d_6\">\n",
       "    <path clip-path=\"url(#p2a9c33704d)\" d=\"M 120.585827 52.554331 \n",
       "L 120.585827 75.231496 \n",
       "\" style=\"fill:none;stroke:#000000;stroke-linecap:square;\"/>\n",
       "   </g>\n",
       "   <g id=\"matplotlib.axis_1\"/>\n",
       "   <g id=\"matplotlib.axis_2\"/>\n",
       "   <g id=\"text_1\">\n",
       "    <!-- A -->\n",
       "    <defs>\n",
       "     <path d=\"M 34.1875 63.1875 \n",
       "L 20.796875 26.90625 \n",
       "L 47.609375 26.90625 \n",
       "z\n",
       "M 28.609375 72.90625 \n",
       "L 39.796875 72.90625 \n",
       "L 67.578125 0 \n",
       "L 57.328125 0 \n",
       "L 50.6875 18.703125 \n",
       "L 17.828125 18.703125 \n",
       "L 11.1875 0 \n",
       "L 0.78125 0 \n",
       "z\n",
       "\" id=\"BitstreamVeraSans-Roman-41\"/>\n",
       "    </defs>\n",
       "    <g transform=\"translate(57.7363508858 40.5133316929)scale(0.18 -0.18)\">\n",
       "     <use xlink:href=\"#BitstreamVeraSans-Roman-41\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"text_2\">\n",
       "    <!-- F -->\n",
       "    <defs>\n",
       "     <path d=\"M 9.8125 72.90625 \n",
       "L 51.703125 72.90625 \n",
       "L 51.703125 64.59375 \n",
       "L 19.671875 64.59375 \n",
       "L 19.671875 43.109375 \n",
       "L 48.578125 43.109375 \n",
       "L 48.578125 34.8125 \n",
       "L 19.671875 34.8125 \n",
       "L 19.671875 0 \n",
       "L 9.8125 0 \n",
       "z\n",
       "\" id=\"BitstreamVeraSans-Roman-46\"/>\n",
       "    </defs>\n",
       "    <g transform=\"translate(115.409420522 40.5133316929)scale(0.18 -0.18)\">\n",
       "     <use xlink:href=\"#BitstreamVeraSans-Roman-46\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"text_3\">\n",
       "    <!-- C -->\n",
       "    <defs>\n",
       "     <path d=\"M 64.40625 67.28125 \n",
       "L 64.40625 56.890625 \n",
       "Q 59.421875 61.53125 53.78125 63.8125 \n",
       "Q 48.140625 66.109375 41.796875 66.109375 \n",
       "Q 29.296875 66.109375 22.65625 58.46875 \n",
       "Q 16.015625 50.828125 16.015625 36.375 \n",
       "Q 16.015625 21.96875 22.65625 14.328125 \n",
       "Q 29.296875 6.6875 41.796875 6.6875 \n",
       "Q 48.140625 6.6875 53.78125 8.984375 \n",
       "Q 59.421875 11.28125 64.40625 15.921875 \n",
       "L 64.40625 5.609375 \n",
       "Q 59.234375 2.09375 53.4375 0.328125 \n",
       "Q 47.65625 -1.421875 41.21875 -1.421875 \n",
       "Q 24.65625 -1.421875 15.125 8.703125 \n",
       "Q 5.609375 18.84375 5.609375 36.375 \n",
       "Q 5.609375 53.953125 15.125 64.078125 \n",
       "Q 24.65625 74.21875 41.21875 74.21875 \n",
       "Q 47.75 74.21875 53.53125 72.484375 \n",
       "Q 59.328125 70.75 64.40625 67.28125 \n",
       "\" id=\"BitstreamVeraSans-Roman-43\"/>\n",
       "    </defs>\n",
       "    <g transform=\"translate(57.6083821358 97.2062450787)scale(0.18 -0.18)\">\n",
       "     <use xlink:href=\"#BitstreamVeraSans-Roman-43\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"text_4\">\n",
       "    <!-- D -->\n",
       "    <defs>\n",
       "     <path d=\"M 19.671875 64.796875 \n",
       "L 19.671875 8.109375 \n",
       "L 31.59375 8.109375 \n",
       "Q 46.6875 8.109375 53.6875 14.9375 \n",
       "Q 60.6875 21.78125 60.6875 36.53125 \n",
       "Q 60.6875 51.171875 53.6875 57.984375 \n",
       "Q 46.6875 64.796875 31.59375 64.796875 \n",
       "z\n",
       "M 9.8125 72.90625 \n",
       "L 30.078125 72.90625 \n",
       "Q 51.265625 72.90625 61.171875 64.09375 \n",
       "Q 71.09375 55.28125 71.09375 36.53125 \n",
       "Q 71.09375 17.671875 61.125 8.828125 \n",
       "Q 51.171875 0 30.078125 0 \n",
       "L 9.8125 0 \n",
       "z\n",
       "\" id=\"BitstreamVeraSans-Roman-44\"/>\n",
       "    </defs>\n",
       "    <g transform=\"translate(28.6164566929 68.8597883858)scale(0.18 -0.18)\">\n",
       "     <use xlink:href=\"#BitstreamVeraSans-Roman-44\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"text_5\">\n",
       "    <!-- B -->\n",
       "    <defs>\n",
       "     <path d=\"M 19.671875 34.8125 \n",
       "L 19.671875 8.109375 \n",
       "L 35.5 8.109375 \n",
       "Q 43.453125 8.109375 47.28125 11.40625 \n",
       "Q 51.125 14.703125 51.125 21.484375 \n",
       "Q 51.125 28.328125 47.28125 31.5625 \n",
       "Q 43.453125 34.8125 35.5 34.8125 \n",
       "z\n",
       "M 19.671875 64.796875 \n",
       "L 19.671875 42.828125 \n",
       "L 34.28125 42.828125 \n",
       "Q 41.5 42.828125 45.03125 45.53125 \n",
       "Q 48.578125 48.25 48.578125 53.8125 \n",
       "Q 48.578125 59.328125 45.03125 62.0625 \n",
       "Q 41.5 64.796875 34.28125 64.796875 \n",
       "z\n",
       "M 9.8125 72.90625 \n",
       "L 35.015625 72.90625 \n",
       "Q 46.296875 72.90625 52.390625 68.21875 \n",
       "Q 58.5 63.53125 58.5 54.890625 \n",
       "Q 58.5 48.1875 55.375 44.234375 \n",
       "Q 52.25 40.28125 46.1875 39.3125 \n",
       "Q 53.46875 37.75 57.5 32.78125 \n",
       "Q 61.53125 27.828125 61.53125 20.40625 \n",
       "Q 61.53125 10.640625 54.890625 5.3125 \n",
       "Q 48.25 0 35.984375 0 \n",
       "L 9.8125 0 \n",
       "z\n",
       "\" id=\"BitstreamVeraSans-Roman-42\"/>\n",
       "    </defs>\n",
       "    <g transform=\"translate(86.0645263287 68.8597883858)scale(0.18 -0.18)\">\n",
       "     <use xlink:href=\"#BitstreamVeraSans-Roman-42\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"text_6\">\n",
       "    <!-- E -->\n",
       "    <defs>\n",
       "     <path d=\"M 9.8125 72.90625 \n",
       "L 55.90625 72.90625 \n",
       "L 55.90625 64.59375 \n",
       "L 19.671875 64.59375 \n",
       "L 19.671875 43.015625 \n",
       "L 54.390625 43.015625 \n",
       "L 54.390625 34.71875 \n",
       "L 19.671875 34.71875 \n",
       "L 19.671875 8.296875 \n",
       "L 56.78125 8.296875 \n",
       "L 56.78125 0 \n",
       "L 9.8125 0 \n",
       "z\n",
       "\" id=\"BitstreamVeraSans-Roman-45\"/>\n",
       "    </defs>\n",
       "    <g transform=\"translate(114.898951772 97.2062450787)scale(0.18 -0.18)\">\n",
       "     <use xlink:href=\"#BitstreamVeraSans-Roman-45\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "  </g>\n",
       " </g>\n",
       " <defs>\n",
       "  <clipPath id=\"p2a9c33704d\">\n",
       "   <rect height=\"113.385826772\" width=\"170.078740157\" x=\"7.2\" y=\"7.2\"/>\n",
       "  </clipPath>\n",
       " </defs>\n",
       "</svg>\n"
      ],
      "text/plain": [
       "<matplotlib.figure.Figure at 0x7feb969d4a20>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "pgm = daft.PGM([3, 2], origin=[-0.5, 0.5], directed=False)\n",
    "add_node(pgm, 'a', 'A', 0.5, 2)\n",
    "add_node(pgm, 'b', 'B', 1, 1.5)\n",
    "add_node(pgm, 'c', 'C', 0.5, 1)\n",
    "add_node(pgm, 'd', 'D', 0, 1.5)\n",
    "add_node(pgm, 'e', 'E', 1.5, 1)\n",
    "add_node(pgm, 'f', 'F', 1.5, 2)\n",
    "add_edges(pgm, [\n",
    "        ('d', 'a'),\n",
    "        ('c', 'd'),\n",
    "        ('b', 'd'),\n",
    "        ('b', 'f'),\n",
    "        ('b', 'e'),\n",
    "        ('f', 'e')\n",
    "    ])\n",
    "pgm.render()\n",
    "save('markov_network_separation')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 58,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "image/svg+xml": [
       "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"no\"?>\n",
       "<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\n",
       "  \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n",
       "<!-- Created with matplotlib (http://matplotlib.org/) -->\n",
       "<svg height=\"127pt\" version=\"1.1\" viewBox=\"0 0 156 127\" width=\"156pt\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n",
       " <defs>\n",
       "  <style type=\"text/css\">\n",
       "*{stroke-linecap:butt;stroke-linejoin:round;stroke-miterlimit:100000;}\n",
       "  </style>\n",
       " </defs>\n",
       " <g id=\"figure_1\">\n",
       "  <g id=\"patch_1\">\n",
       "   <path d=\"M 0 127.785827 \n",
       "L 156.132283 127.785827 \n",
       "L 156.132283 0 \n",
       "L 0 0 \n",
       "L 0 127.785827 \n",
       "z\n",
       "\" style=\"fill:none;\"/>\n",
       "  </g>\n",
       "  <g id=\"axes_1\">\n",
       "   <g id=\"patch_2\">\n",
       "    <path clip-path=\"url(#p06821e6e87)\" d=\"M 116.050394 49.152756 \n",
       "L 116.050394 52.696063 \n",
       "L 114.349606 51.420472 \n",
       "L 102.444094 67.294488 \n",
       "L 102.444094 67.294488 \n",
       "L 114.349606 51.420472 \n",
       "L 112.648819 50.144882 \n",
       "L 116.050394 49.152756 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_3\">\n",
       "    <path clip-path=\"url(#p06821e6e87)\" d=\"M 68.428346 49.152756 \n",
       "L 71.829921 50.144882 \n",
       "L 70.129134 51.420472 \n",
       "L 82.034646 67.294488 \n",
       "L 82.034646 67.294488 \n",
       "L 70.129134 51.420472 \n",
       "L 68.428346 52.696063 \n",
       "L 68.428346 49.152756 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_4\">\n",
       "    <path clip-path=\"url(#p06821e6e87)\" d=\"M 92.23937 97.908661 \n",
       "C 96.749911 97.908661 101.076319 96.116605 104.265753 92.92717 \n",
       "C 107.455187 89.737736 109.247244 85.411328 109.247244 80.900787 \n",
       "C 109.247244 76.390246 107.455187 72.063838 104.265753 68.874404 \n",
       "C 101.076319 65.68497 96.749911 63.892913 92.23937 63.892913 \n",
       "C 87.728829 63.892913 83.402421 65.68497 80.212987 68.874404 \n",
       "C 77.023553 72.063838 75.231496 76.390246 75.231496 80.900787 \n",
       "C 75.231496 85.411328 77.023553 89.737736 80.212987 92.92717 \n",
       "C 83.402421 96.116605 87.728829 97.908661 92.23937 97.908661 \n",
       "L 92.23937 97.908661 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_5\">\n",
       "    <path clip-path=\"url(#p06821e6e87)\" d=\"M 58.223622 52.554331 \n",
       "C 62.734163 52.554331 67.060571 50.762274 70.250005 47.57284 \n",
       "C 73.439439 44.383406 75.231496 40.056998 75.231496 35.546457 \n",
       "C 75.231496 31.035916 73.439439 26.709508 70.250005 23.520074 \n",
       "C 67.060571 20.33064 62.734163 18.538583 58.223622 18.538583 \n",
       "C 53.713081 18.538583 49.386673 20.33064 46.197239 23.520074 \n",
       "C 43.007805 26.709508 41.215748 31.035916 41.215748 35.546457 \n",
       "C 41.215748 40.056998 43.007805 44.383406 46.197239 47.57284 \n",
       "C 49.386673 50.762274 53.713081 52.554331 58.223622 52.554331 \n",
       "L 58.223622 52.554331 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_6\">\n",
       "    <path clip-path=\"url(#p06821e6e87)\" d=\"M 126.255118 52.554331 \n",
       "C 130.765659 52.554331 135.092067 50.762274 138.281501 47.57284 \n",
       "C 141.470935 44.383406 143.262992 40.056998 143.262992 35.546457 \n",
       "C 143.262992 31.035916 141.470935 26.709508 138.281501 23.520074 \n",
       "C 135.092067 20.33064 130.765659 18.538583 126.255118 18.538583 \n",
       "C 121.744577 18.538583 117.418169 20.33064 114.228735 23.520074 \n",
       "C 111.039301 26.709508 109.247244 31.035916 109.247244 35.546457 \n",
       "C 109.247244 40.056998 111.039301 44.383406 114.228735 47.57284 \n",
       "C 117.418169 50.762274 121.744577 52.554331 126.255118 52.554331 \n",
       "L 126.255118 52.554331 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"matplotlib.axis_1\"/>\n",
       "   <g id=\"matplotlib.axis_2\"/>\n",
       "   <g id=\"text_1\">\n",
       "    <!-- Y -->\n",
       "    <defs>\n",
       "     <path d=\"M -0.203125 72.90625 \n",
       "L 10.40625 72.90625 \n",
       "L 30.609375 42.921875 \n",
       "L 50.6875 72.90625 \n",
       "L 61.28125 72.90625 \n",
       "L 35.5 34.71875 \n",
       "L 35.5 0 \n",
       "L 25.59375 0 \n",
       "L 25.59375 34.71875 \n",
       "z\n",
       "\" id=\"BitstreamVeraSans-Roman-59\"/>\n",
       "    </defs>\n",
       "    <g transform=\"translate(86.7423388287 85.8676624016)scale(0.18 -0.18)\">\n",
       "     <use xlink:href=\"#BitstreamVeraSans-Roman-59\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"text_2\">\n",
       "    <!-- Z -->\n",
       "    <defs>\n",
       "     <path d=\"M 5.609375 72.90625 \n",
       "L 62.890625 72.90625 \n",
       "L 62.890625 65.375 \n",
       "L 16.796875 8.296875 \n",
       "L 64.015625 8.296875 \n",
       "L 64.015625 0 \n",
       "L 4.5 0 \n",
       "L 4.5 7.515625 \n",
       "L 50.59375 64.59375 \n",
       "L 5.609375 64.59375 \n",
       "z\n",
       "\" id=\"BitstreamVeraSans-Roman-5a\"/>\n",
       "    </defs>\n",
       "    <g transform=\"translate(52.0586220472 40.5133316929)scale(0.18 -0.18)\">\n",
       "     <use xlink:href=\"#BitstreamVeraSans-Roman-5a\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"text_3\">\n",
       "    <!-- X -->\n",
       "    <defs>\n",
       "     <path d=\"M 6.296875 72.90625 \n",
       "L 16.890625 72.90625 \n",
       "L 35.015625 45.796875 \n",
       "L 53.21875 72.90625 \n",
       "L 63.8125 72.90625 \n",
       "L 40.375 37.890625 \n",
       "L 65.375 0 \n",
       "L 54.78125 0 \n",
       "L 34.28125 31 \n",
       "L 13.625 0 \n",
       "L 2.984375 0 \n",
       "L 29 38.921875 \n",
       "z\n",
       "\" id=\"BitstreamVeraSans-Roman-58\"/>\n",
       "    </defs>\n",
       "    <g transform=\"translate(120.09011811 40.5133316929)scale(0.18 -0.18)\">\n",
       "     <use xlink:href=\"#BitstreamVeraSans-Roman-58\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "  </g>\n",
       " </g>\n",
       " <defs>\n",
       "  <clipPath id=\"p06821e6e87\">\n",
       "   <rect height=\"113.385826772\" width=\"141.732283465\" x=\"7.2\" y=\"7.2\"/>\n",
       "  </clipPath>\n",
       " </defs>\n",
       "</svg>\n"
      ],
      "text/plain": [
       "<matplotlib.figure.Figure at 0x7feb96e49ef0>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "pgm = daft.PGM([2.5, 2], origin=[-0.5, 0.5])\n",
    "add_node(pgm, 'Z', 'Z', 0.4, 2)\n",
    "add_node(pgm, 'Y', 'Y', 1, 1.2)\n",
    "add_node(pgm, 'X', 'X', 1.6, 2)\n",
    "add_edges(pgm, [\n",
    "        ('Y', 'X'),\n",
    "        ('Y', 'Z'),\n",
    "    ])\n",
    "pgm.render()\n",
    "save('common_cause')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "image/svg+xml": [
       "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"no\"?>\n",
       "<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\n",
       "  \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n",
       "<!-- Created with matplotlib (http://matplotlib.org/) -->\n",
       "<svg height=\"127pt\" version=\"1.1\" viewBox=\"0 0 156 127\" width=\"156pt\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n",
       " <defs>\n",
       "  <style type=\"text/css\">\n",
       "*{stroke-linecap:butt;stroke-linejoin:round;stroke-miterlimit:100000;}\n",
       "  </style>\n",
       " </defs>\n",
       " <g id=\"figure_1\">\n",
       "  <g id=\"patch_1\">\n",
       "   <path d=\"M 0 127.785827 \n",
       "L 156.132283 127.785827 \n",
       "L 156.132283 0 \n",
       "L 0 0 \n",
       "L 0 127.785827 \n",
       "z\n",
       "\" style=\"fill:none;\"/>\n",
       "  </g>\n",
       "  <g id=\"axes_1\">\n",
       "   <g id=\"patch_2\">\n",
       "    <path clip-path=\"url(#pfa871add6b)\" d=\"M 102.444094 67.294488 \n",
       "L 102.444094 63.751181 \n",
       "L 104.144882 65.026772 \n",
       "L 116.050394 49.152756 \n",
       "L 116.050394 49.152756 \n",
       "L 104.144882 65.026772 \n",
       "L 105.845669 66.302362 \n",
       "L 102.444094 67.294488 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_3\">\n",
       "    <path clip-path=\"url(#pfa871add6b)\" d=\"M 82.034646 67.294488 \n",
       "L 78.633071 66.302362 \n",
       "L 80.333858 65.026772 \n",
       "L 68.428346 49.152756 \n",
       "L 68.428346 49.152756 \n",
       "L 80.333858 65.026772 \n",
       "L 82.034646 63.751181 \n",
       "L 82.034646 67.294488 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_4\">\n",
       "    <path clip-path=\"url(#pfa871add6b)\" d=\"M 126.255118 52.554331 \n",
       "C 130.765659 52.554331 135.092067 50.762274 138.281501 47.57284 \n",
       "C 141.470935 44.383406 143.262992 40.056998 143.262992 35.546457 \n",
       "C 143.262992 31.035916 141.470935 26.709508 138.281501 23.520074 \n",
       "C 135.092067 20.33064 130.765659 18.538583 126.255118 18.538583 \n",
       "C 121.744577 18.538583 117.418169 20.33064 114.228735 23.520074 \n",
       "C 111.039301 26.709508 109.247244 31.035916 109.247244 35.546457 \n",
       "C 109.247244 40.056998 111.039301 44.383406 114.228735 47.57284 \n",
       "C 117.418169 50.762274 121.744577 52.554331 126.255118 52.554331 \n",
       "L 126.255118 52.554331 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_5\">\n",
       "    <path clip-path=\"url(#pfa871add6b)\" d=\"M 58.223622 52.554331 \n",
       "C 62.734163 52.554331 67.060571 50.762274 70.250005 47.57284 \n",
       "C 73.439439 44.383406 75.231496 40.056998 75.231496 35.546457 \n",
       "C 75.231496 31.035916 73.439439 26.709508 70.250005 23.520074 \n",
       "C 67.060571 20.33064 62.734163 18.538583 58.223622 18.538583 \n",
       "C 53.713081 18.538583 49.386673 20.33064 46.197239 23.520074 \n",
       "C 43.007805 26.709508 41.215748 31.035916 41.215748 35.546457 \n",
       "C 41.215748 40.056998 43.007805 44.383406 46.197239 47.57284 \n",
       "C 49.386673 50.762274 53.713081 52.554331 58.223622 52.554331 \n",
       "L 58.223622 52.554331 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_6\">\n",
       "    <path clip-path=\"url(#pfa871add6b)\" d=\"M 92.23937 97.908661 \n",
       "C 96.749911 97.908661 101.076319 96.116605 104.265753 92.92717 \n",
       "C 107.455187 89.737736 109.247244 85.411328 109.247244 80.900787 \n",
       "C 109.247244 76.390246 107.455187 72.063838 104.265753 68.874404 \n",
       "C 101.076319 65.68497 96.749911 63.892913 92.23937 63.892913 \n",
       "C 87.728829 63.892913 83.402421 65.68497 80.212987 68.874404 \n",
       "C 77.023553 72.063838 75.231496 76.390246 75.231496 80.900787 \n",
       "C 75.231496 85.411328 77.023553 89.737736 80.212987 92.92717 \n",
       "C 83.402421 96.116605 87.728829 97.908661 92.23937 97.908661 \n",
       "L 92.23937 97.908661 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"matplotlib.axis_1\"/>\n",
       "   <g id=\"matplotlib.axis_2\"/>\n",
       "   <g id=\"text_1\">\n",
       "    <!-- X -->\n",
       "    <defs>\n",
       "     <path d=\"M 6.296875 72.90625 \n",
       "L 16.890625 72.90625 \n",
       "L 35.015625 45.796875 \n",
       "L 53.21875 72.90625 \n",
       "L 63.8125 72.90625 \n",
       "L 40.375 37.890625 \n",
       "L 65.375 0 \n",
       "L 54.78125 0 \n",
       "L 34.28125 31 \n",
       "L 13.625 0 \n",
       "L 2.984375 0 \n",
       "L 29 38.921875 \n",
       "z\n",
       "\" id=\"BitstreamVeraSans-Roman-58\"/>\n",
       "    </defs>\n",
       "    <g transform=\"translate(120.09011811 40.5133316929)scale(0.18 -0.18)\">\n",
       "     <use xlink:href=\"#BitstreamVeraSans-Roman-58\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"text_2\">\n",
       "    <!-- Y -->\n",
       "    <defs>\n",
       "     <path d=\"M -0.203125 72.90625 \n",
       "L 10.40625 72.90625 \n",
       "L 30.609375 42.921875 \n",
       "L 50.6875 72.90625 \n",
       "L 61.28125 72.90625 \n",
       "L 35.5 34.71875 \n",
       "L 35.5 0 \n",
       "L 25.59375 0 \n",
       "L 25.59375 34.71875 \n",
       "z\n",
       "\" id=\"BitstreamVeraSans-Roman-59\"/>\n",
       "    </defs>\n",
       "    <g transform=\"translate(52.7265907972 40.5133316929)scale(0.18 -0.18)\">\n",
       "     <use xlink:href=\"#BitstreamVeraSans-Roman-59\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"text_3\">\n",
       "    <!-- Z -->\n",
       "    <defs>\n",
       "     <path d=\"M 5.609375 72.90625 \n",
       "L 62.890625 72.90625 \n",
       "L 62.890625 65.375 \n",
       "L 16.796875 8.296875 \n",
       "L 64.015625 8.296875 \n",
       "L 64.015625 0 \n",
       "L 4.5 0 \n",
       "L 4.5 7.515625 \n",
       "L 50.59375 64.59375 \n",
       "L 5.609375 64.59375 \n",
       "z\n",
       "\" id=\"BitstreamVeraSans-Roman-5a\"/>\n",
       "    </defs>\n",
       "    <g transform=\"translate(86.0743700787 85.8676624016)scale(0.18 -0.18)\">\n",
       "     <use xlink:href=\"#BitstreamVeraSans-Roman-5a\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "  </g>\n",
       " </g>\n",
       " <defs>\n",
       "  <clipPath id=\"pfa871add6b\">\n",
       "   <rect height=\"113.385826772\" width=\"141.732283465\" x=\"7.2\" y=\"7.2\"/>\n",
       "  </clipPath>\n",
       " </defs>\n",
       "</svg>\n"
      ],
      "text/plain": [
       "<matplotlib.figure.Figure at 0x7f88ed1ed7f0>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "pgm = daft.PGM([2.5, 2], origin=[-0.5, 0.5])\n",
    "add_node(pgm, 'Y', 'Y', 0.4, 2)\n",
    "add_node(pgm, 'Z', 'Z', 1, 1.2)\n",
    "add_node(pgm, 'X', 'X', 1.6, 2)\n",
    "add_edges(pgm, [\n",
    "        ('X', 'Z'),\n",
    "        ('Y', 'Z'),\n",
    "    ])\n",
    "pgm.render()\n",
    "save('common_effect')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "image/svg+xml": [
       "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"no\"?>\n",
       "<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\n",
       "  \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n",
       "<!-- Created with matplotlib (http://matplotlib.org/) -->\n",
       "<svg height=\"127pt\" version=\"1.1\" viewBox=\"0 0 241 127\" width=\"241pt\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n",
       " <defs>\n",
       "  <style type=\"text/css\">\n",
       "*{stroke-linecap:butt;stroke-linejoin:round;stroke-miterlimit:100000;}\n",
       "  </style>\n",
       " </defs>\n",
       " <g id=\"figure_1\">\n",
       "  <g id=\"patch_1\">\n",
       "   <path d=\"M 0 127.785827 \n",
       "L 241.171654 127.785827 \n",
       "L 241.171654 0 \n",
       "L 0 0 \n",
       "L 0 127.785827 \n",
       "z\n",
       "\" style=\"fill:none;\"/>\n",
       "  </g>\n",
       "  <g id=\"axes_1\">\n",
       "   <g id=\"patch_2\">\n",
       "    <path clip-path=\"url(#p2eec64de01)\" d=\"M 75.231496 80.900787 \n",
       "L 72.39685 83.026772 \n",
       "L 72.39685 80.900787 \n",
       "L 52.554331 80.900787 \n",
       "L 52.554331 80.900787 \n",
       "L 72.39685 80.900787 \n",
       "L 72.39685 78.774803 \n",
       "L 75.231496 80.900787 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_3\">\n",
       "    <path clip-path=\"url(#p2eec64de01)\" d=\"M 92.23937 52.554331 \n",
       "L 94.365354 55.388976 \n",
       "L 92.23937 55.388976 \n",
       "L 92.23937 63.892913 \n",
       "L 92.23937 63.892913 \n",
       "L 92.23937 55.388976 \n",
       "L 90.113386 55.388976 \n",
       "L 92.23937 52.554331 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_4\">\n",
       "    <path clip-path=\"url(#p2eec64de01)\" d=\"M 131.924409 80.900787 \n",
       "L 129.089764 83.026772 \n",
       "L 129.089764 80.900787 \n",
       "L 109.247244 80.900787 \n",
       "L 109.247244 80.900787 \n",
       "L 129.089764 80.900787 \n",
       "L 129.089764 78.774803 \n",
       "L 131.924409 80.900787 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_5\">\n",
       "    <path clip-path=\"url(#p2eec64de01)\" d=\"M 148.932283 63.892913 \n",
       "L 146.806299 61.058268 \n",
       "L 148.932283 61.058268 \n",
       "L 148.932283 52.554331 \n",
       "L 148.932283 52.554331 \n",
       "L 148.932283 61.058268 \n",
       "L 151.058268 61.058268 \n",
       "L 148.932283 63.892913 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_6\">\n",
       "    <path clip-path=\"url(#p2eec64de01)\" d=\"M 35.546457 97.908661 \n",
       "C 40.056998 97.908661 44.383406 96.116605 47.57284 92.92717 \n",
       "C 50.762274 89.737736 52.554331 85.411328 52.554331 80.900787 \n",
       "C 52.554331 76.390246 50.762274 72.063838 47.57284 68.874404 \n",
       "C 44.383406 65.68497 40.056998 63.892913 35.546457 63.892913 \n",
       "C 31.035916 63.892913 26.709508 65.68497 23.520074 68.874404 \n",
       "C 20.33064 72.063838 18.538583 76.390246 18.538583 80.900787 \n",
       "C 18.538583 85.411328 20.33064 89.737736 23.520074 92.92717 \n",
       "C 26.709508 96.116605 31.035916 97.908661 35.546457 97.908661 \n",
       "L 35.546457 97.908661 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_7\">\n",
       "    <path clip-path=\"url(#p2eec64de01)\" d=\"M 92.23937 97.908661 \n",
       "C 96.749911 97.908661 101.076319 96.116605 104.265753 92.92717 \n",
       "C 107.455187 89.737736 109.247244 85.411328 109.247244 80.900787 \n",
       "C 109.247244 76.390246 107.455187 72.063838 104.265753 68.874404 \n",
       "C 101.076319 65.68497 96.749911 63.892913 92.23937 63.892913 \n",
       "C 87.728829 63.892913 83.402421 65.68497 80.212987 68.874404 \n",
       "C 77.023553 72.063838 75.231496 76.390246 75.231496 80.900787 \n",
       "C 75.231496 85.411328 77.023553 89.737736 80.212987 92.92717 \n",
       "C 83.402421 96.116605 87.728829 97.908661 92.23937 97.908661 \n",
       "L 92.23937 97.908661 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_8\">\n",
       "    <path clip-path=\"url(#p2eec64de01)\" d=\"M 148.932283 97.908661 \n",
       "C 153.442824 97.908661 157.769232 96.116605 160.958667 92.92717 \n",
       "C 164.148101 89.737736 165.940157 85.411328 165.940157 80.900787 \n",
       "C 165.940157 76.390246 164.148101 72.063838 160.958667 68.874404 \n",
       "C 157.769232 65.68497 153.442824 63.892913 148.932283 63.892913 \n",
       "C 144.421743 63.892913 140.095334 65.68497 136.9059 68.874404 \n",
       "C 133.716466 72.063838 131.924409 76.390246 131.924409 80.900787 \n",
       "C 131.924409 85.411328 133.716466 89.737736 136.9059 92.92717 \n",
       "C 140.095334 96.116605 144.421743 97.908661 148.932283 97.908661 \n",
       "L 148.932283 97.908661 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_9\">\n",
       "    <path clip-path=\"url(#p2eec64de01)\" d=\"M 148.932283 52.554331 \n",
       "C 153.442824 52.554331 157.769232 50.762274 160.958667 47.57284 \n",
       "C 164.148101 44.383406 165.940157 40.056998 165.940157 35.546457 \n",
       "C 165.940157 31.035916 164.148101 26.709508 160.958667 23.520074 \n",
       "C 157.769232 20.33064 153.442824 18.538583 148.932283 18.538583 \n",
       "C 144.421743 18.538583 140.095334 20.33064 136.9059 23.520074 \n",
       "C 133.716466 26.709508 131.924409 31.035916 131.924409 35.546457 \n",
       "C 131.924409 40.056998 133.716466 44.383406 136.9059 47.57284 \n",
       "C 140.095334 50.762274 144.421743 52.554331 148.932283 52.554331 \n",
       "L 148.932283 52.554331 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_10\">\n",
       "    <path clip-path=\"url(#p2eec64de01)\" d=\"M 92.23937 52.554331 \n",
       "C 96.749911 52.554331 101.076319 50.762274 104.265753 47.57284 \n",
       "C 107.455187 44.383406 109.247244 40.056998 109.247244 35.546457 \n",
       "C 109.247244 31.035916 107.455187 26.709508 104.265753 23.520074 \n",
       "C 101.076319 20.33064 96.749911 18.538583 92.23937 18.538583 \n",
       "C 87.728829 18.538583 83.402421 20.33064 80.212987 23.520074 \n",
       "C 77.023553 26.709508 75.231496 31.035916 75.231496 35.546457 \n",
       "C 75.231496 40.056998 77.023553 44.383406 80.212987 47.57284 \n",
       "C 83.402421 50.762274 87.728829 52.554331 92.23937 52.554331 \n",
       "L 92.23937 52.554331 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"matplotlib.axis_1\"/>\n",
       "   <g id=\"matplotlib.axis_2\"/>\n",
       "   <g id=\"text_1\">\n",
       "    <!-- L -->\n",
       "    <defs>\n",
       "     <path d=\"M 9.8125 72.90625 \n",
       "L 19.671875 72.90625 \n",
       "L 19.671875 8.296875 \n",
       "L 55.171875 8.296875 \n",
       "L 55.171875 0 \n",
       "L 9.8125 0 \n",
       "z\n",
       "\" id=\"BitstreamVeraSans-Roman-4c\"/>\n",
       "    </defs>\n",
       "    <g transform=\"translate(30.5317691929 85.8676624016)scale(0.18 -0.18)\">\n",
       "     <use xlink:href=\"#BitstreamVeraSans-Roman-4c\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"text_2\">\n",
       "    <!-- R -->\n",
       "    <defs>\n",
       "     <path d=\"M 44.390625 34.1875 \n",
       "Q 47.5625 33.109375 50.5625 29.59375 \n",
       "Q 53.5625 26.078125 56.59375 19.921875 \n",
       "L 66.609375 0 \n",
       "L 56 0 \n",
       "L 46.6875 18.703125 \n",
       "Q 43.0625 26.03125 39.671875 28.421875 \n",
       "Q 36.28125 30.8125 30.421875 30.8125 \n",
       "L 19.671875 30.8125 \n",
       "L 19.671875 0 \n",
       "L 9.8125 0 \n",
       "L 9.8125 72.90625 \n",
       "L 32.078125 72.90625 \n",
       "Q 44.578125 72.90625 50.734375 67.671875 \n",
       "Q 56.890625 62.453125 56.890625 51.90625 \n",
       "Q 56.890625 45.015625 53.6875 40.46875 \n",
       "Q 50.484375 35.9375 44.390625 34.1875 \n",
       "M 19.671875 64.796875 \n",
       "L 19.671875 38.921875 \n",
       "L 32.078125 38.921875 \n",
       "Q 39.203125 38.921875 42.84375 42.21875 \n",
       "Q 46.484375 45.515625 46.484375 51.90625 \n",
       "Q 46.484375 58.296875 42.84375 61.546875 \n",
       "Q 39.203125 64.796875 32.078125 64.796875 \n",
       "z\n",
       "\" id=\"BitstreamVeraSans-Roman-52\"/>\n",
       "    </defs>\n",
       "    <g transform=\"translate(85.9857763287 85.8676624016)scale(0.18 -0.18)\">\n",
       "     <use xlink:href=\"#BitstreamVeraSans-Roman-52\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"text_3\">\n",
       "    <!-- T -->\n",
       "    <defs>\n",
       "     <path d=\"M -0.296875 72.90625 \n",
       "L 61.375 72.90625 \n",
       "L 61.375 64.59375 \n",
       "L 35.5 64.59375 \n",
       "L 35.5 0 \n",
       "L 25.59375 0 \n",
       "L 25.59375 64.59375 \n",
       "L -0.296875 64.59375 \n",
       "z\n",
       "\" id=\"BitstreamVeraSans-Roman-54\"/>\n",
       "    </defs>\n",
       "    <g transform=\"translate(143.435252215 85.8676624016)scale(0.18 -0.18)\">\n",
       "     <use xlink:href=\"#BitstreamVeraSans-Roman-54\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"text_4\">\n",
       "    <!-- B -->\n",
       "    <defs>\n",
       "     <path d=\"M 19.671875 34.8125 \n",
       "L 19.671875 8.109375 \n",
       "L 35.5 8.109375 \n",
       "Q 43.453125 8.109375 47.28125 11.40625 \n",
       "Q 51.125 14.703125 51.125 21.484375 \n",
       "Q 51.125 28.328125 47.28125 31.5625 \n",
       "Q 43.453125 34.8125 35.5 34.8125 \n",
       "z\n",
       "M 19.671875 64.796875 \n",
       "L 19.671875 42.828125 \n",
       "L 34.28125 42.828125 \n",
       "Q 41.5 42.828125 45.03125 45.53125 \n",
       "Q 48.578125 48.25 48.578125 53.8125 \n",
       "Q 48.578125 59.328125 45.03125 62.0625 \n",
       "Q 41.5 64.796875 34.28125 64.796875 \n",
       "z\n",
       "M 9.8125 72.90625 \n",
       "L 35.015625 72.90625 \n",
       "Q 46.296875 72.90625 52.390625 68.21875 \n",
       "Q 58.5 63.53125 58.5 54.890625 \n",
       "Q 58.5 48.1875 55.375 44.234375 \n",
       "Q 52.25 40.28125 46.1875 39.3125 \n",
       "Q 53.46875 37.75 57.5 32.78125 \n",
       "Q 61.53125 27.828125 61.53125 20.40625 \n",
       "Q 61.53125 10.640625 54.890625 5.3125 \n",
       "Q 48.25 0 35.984375 0 \n",
       "L 9.8125 0 \n",
       "z\n",
       "\" id=\"BitstreamVeraSans-Roman-42\"/>\n",
       "    </defs>\n",
       "    <g transform=\"translate(142.757439715 40.5133316929)scale(0.18 -0.18)\">\n",
       "     <use xlink:href=\"#BitstreamVeraSans-Roman-42\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"text_5\">\n",
       "    <!-- D -->\n",
       "    <defs>\n",
       "     <path d=\"M 19.671875 64.796875 \n",
       "L 19.671875 8.109375 \n",
       "L 31.59375 8.109375 \n",
       "Q 46.6875 8.109375 53.6875 14.9375 \n",
       "Q 60.6875 21.78125 60.6875 36.53125 \n",
       "Q 60.6875 51.171875 53.6875 57.984375 \n",
       "Q 46.6875 64.796875 31.59375 64.796875 \n",
       "z\n",
       "M 9.8125 72.90625 \n",
       "L 30.078125 72.90625 \n",
       "Q 51.265625 72.90625 61.171875 64.09375 \n",
       "Q 71.09375 55.28125 71.09375 36.53125 \n",
       "Q 71.09375 17.671875 61.125 8.828125 \n",
       "Q 51.171875 0 30.078125 0 \n",
       "L 9.8125 0 \n",
       "z\n",
       "\" id=\"BitstreamVeraSans-Roman-44\"/>\n",
       "    </defs>\n",
       "    <g transform=\"translate(85.3093700787 40.5133316929)scale(0.18 -0.18)\">\n",
       "     <use xlink:href=\"#BitstreamVeraSans-Roman-44\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "  </g>\n",
       " </g>\n",
       " <defs>\n",
       "  <clipPath id=\"p2eec64de01\">\n",
       "   <rect height=\"113.385826772\" width=\"226.771653543\" x=\"7.2\" y=\"7.2\"/>\n",
       "  </clipPath>\n",
       " </defs>\n",
       "</svg>\n"
      ],
      "text/plain": [
       "<matplotlib.figure.Figure at 0x7f88e33f3240>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "pgm = daft.PGM([4, 2], origin=[-0.5, 0.5])\n",
    "add_node(pgm, 'L', 'L', 0, 1.2)\n",
    "add_node(pgm, 'R', 'R', 1, 1.2)\n",
    "add_node(pgm, 'D', 'D', 1, 2)\n",
    "add_node(pgm, 'T', 'T', 2, 1.2)\n",
    "add_node(pgm, 'B', 'B', 2, 2)\n",
    "add_edges(pgm, [\n",
    "        ('L', 'R'),\n",
    "        ('R', 'D'),\n",
    "        ('R', 'T'),\n",
    "        ('B', 'T')\n",
    "    ])\n",
    "pgm.render()\n",
    "save('example_bayes_net_01')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "image/svg+xml": [
       "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"no\"?>\n",
       "<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\n",
       "  \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n",
       "<!-- Created with matplotlib (http://matplotlib.org/) -->\n",
       "<svg height=\"127pt\" version=\"1.1\" viewBox=\"0 0 297 127\" width=\"297pt\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n",
       " <defs>\n",
       "  <style type=\"text/css\">\n",
       "*{stroke-linecap:butt;stroke-linejoin:round;stroke-miterlimit:100000;}\n",
       "  </style>\n",
       " </defs>\n",
       " <g id=\"figure_1\">\n",
       "  <g id=\"patch_1\">\n",
       "   <path d=\"M 0 127.785827 \n",
       "L 297.864567 127.785827 \n",
       "L 297.864567 0 \n",
       "L 0 0 \n",
       "L 0 127.785827 \n",
       "z\n",
       "\" style=\"fill:none;\"/>\n",
       "  </g>\n",
       "  <g id=\"axes_1\">\n",
       "   <g id=\"patch_2\">\n",
       "    <path clip-path=\"url(#pa6d68d3200)\" d=\"M 76.447955 51.907056 \n",
       "L 73.026482 52.828222 \n",
       "L 73.816053 50.854295 \n",
       "L 51.337871 41.863023 \n",
       "L 51.337871 41.863023 \n",
       "L 73.816053 50.854295 \n",
       "L 74.605624 48.880368 \n",
       "L 76.447955 51.907056 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_3\">\n",
       "    <path clip-path=\"url(#pa6d68d3200)\" d=\"M 76.447955 64.540188 \n",
       "L 74.605624 67.566876 \n",
       "L 73.816053 65.592949 \n",
       "L 51.337871 74.584222 \n",
       "L 51.337871 74.584222 \n",
       "L 73.816053 65.592949 \n",
       "L 73.026482 63.619022 \n",
       "L 76.447955 64.540188 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_4\">\n",
       "    <path clip-path=\"url(#pa6d68d3200)\" d=\"M 131.924409 58.223622 \n",
       "L 129.089764 60.349606 \n",
       "L 129.089764 58.223622 \n",
       "L 109.247244 58.223622 \n",
       "L 109.247244 58.223622 \n",
       "L 129.089764 58.223622 \n",
       "L 129.089764 56.097638 \n",
       "L 131.924409 58.223622 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_5\">\n",
       "    <path clip-path=\"url(#pa6d68d3200)\" d=\"M 188.617323 58.223622 \n",
       "L 185.782677 60.349606 \n",
       "L 185.782677 58.223622 \n",
       "L 165.940157 58.223622 \n",
       "L 165.940157 58.223622 \n",
       "L 185.782677 58.223622 \n",
       "L 185.782677 56.097638 \n",
       "L 188.617323 58.223622 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_6\">\n",
       "    <path clip-path=\"url(#pa6d68d3200)\" d=\"M 245.310236 58.223622 \n",
       "L 242.475591 60.349606 \n",
       "L 242.475591 58.223622 \n",
       "L 222.633071 58.223622 \n",
       "L 222.633071 58.223622 \n",
       "L 242.475591 58.223622 \n",
       "L 242.475591 56.097638 \n",
       "L 245.310236 58.223622 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_7\">\n",
       "    <path clip-path=\"url(#pa6d68d3200)\" d=\"M 92.23937 75.231496 \n",
       "C 96.749911 75.231496 101.076319 73.439439 104.265753 70.250005 \n",
       "C 107.455187 67.060571 109.247244 62.734163 109.247244 58.223622 \n",
       "C 109.247244 53.713081 107.455187 49.386673 104.265753 46.197239 \n",
       "C 101.076319 43.007805 96.749911 41.215748 92.23937 41.215748 \n",
       "C 87.728829 41.215748 83.402421 43.007805 80.212987 46.197239 \n",
       "C 77.023553 49.386673 75.231496 53.713081 75.231496 58.223622 \n",
       "C 75.231496 62.734163 77.023553 67.060571 80.212987 70.250005 \n",
       "C 83.402421 73.439439 87.728829 75.231496 92.23937 75.231496 \n",
       "L 92.23937 75.231496 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_8\">\n",
       "    <path clip-path=\"url(#pa6d68d3200)\" d=\"M 148.932283 75.231496 \n",
       "C 153.442824 75.231496 157.769232 73.439439 160.958667 70.250005 \n",
       "C 164.148101 67.060571 165.940157 62.734163 165.940157 58.223622 \n",
       "C 165.940157 53.713081 164.148101 49.386673 160.958667 46.197239 \n",
       "C 157.769232 43.007805 153.442824 41.215748 148.932283 41.215748 \n",
       "C 144.421743 41.215748 140.095334 43.007805 136.9059 46.197239 \n",
       "C 133.716466 49.386673 131.924409 53.713081 131.924409 58.223622 \n",
       "C 131.924409 62.734163 133.716466 67.060571 136.9059 70.250005 \n",
       "C 140.095334 73.439439 144.421743 75.231496 148.932283 75.231496 \n",
       "L 148.932283 75.231496 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_9\">\n",
       "    <path clip-path=\"url(#pa6d68d3200)\" d=\"M 35.546457 52.554331 \n",
       "C 40.056998 52.554331 44.383406 50.762274 47.57284 47.57284 \n",
       "C 50.762274 44.383406 52.554331 40.056998 52.554331 35.546457 \n",
       "C 52.554331 31.035916 50.762274 26.709508 47.57284 23.520074 \n",
       "C 44.383406 20.33064 40.056998 18.538583 35.546457 18.538583 \n",
       "C 31.035916 18.538583 26.709508 20.33064 23.520074 23.520074 \n",
       "C 20.33064 26.709508 18.538583 31.035916 18.538583 35.546457 \n",
       "C 18.538583 40.056998 20.33064 44.383406 23.520074 47.57284 \n",
       "C 26.709508 50.762274 31.035916 52.554331 35.546457 52.554331 \n",
       "L 35.546457 52.554331 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_10\">\n",
       "    <path clip-path=\"url(#pa6d68d3200)\" d=\"M 35.546457 97.908661 \n",
       "C 40.056998 97.908661 44.383406 96.116605 47.57284 92.92717 \n",
       "C 50.762274 89.737736 52.554331 85.411328 52.554331 80.900787 \n",
       "C 52.554331 76.390246 50.762274 72.063838 47.57284 68.874404 \n",
       "C 44.383406 65.68497 40.056998 63.892913 35.546457 63.892913 \n",
       "C 31.035916 63.892913 26.709508 65.68497 23.520074 68.874404 \n",
       "C 20.33064 72.063838 18.538583 76.390246 18.538583 80.900787 \n",
       "C 18.538583 85.411328 20.33064 89.737736 23.520074 92.92717 \n",
       "C 26.709508 96.116605 31.035916 97.908661 35.546457 97.908661 \n",
       "L 35.546457 97.908661 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_11\">\n",
       "    <path clip-path=\"url(#pa6d68d3200)\" d=\"M 262.31811 75.231496 \n",
       "C 266.828651 75.231496 271.155059 73.439439 274.344493 70.250005 \n",
       "C 277.533927 67.060571 279.325984 62.734163 279.325984 58.223622 \n",
       "C 279.325984 53.713081 277.533927 49.386673 274.344493 46.197239 \n",
       "C 271.155059 43.007805 266.828651 41.215748 262.31811 41.215748 \n",
       "C 257.807569 41.215748 253.481161 43.007805 250.291727 46.197239 \n",
       "C 247.102293 49.386673 245.310236 53.713081 245.310236 58.223622 \n",
       "C 245.310236 62.734163 247.102293 67.060571 250.291727 70.250005 \n",
       "C 253.481161 73.439439 257.807569 75.231496 262.31811 75.231496 \n",
       "L 262.31811 75.231496 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_12\">\n",
       "    <path clip-path=\"url(#pa6d68d3200)\" d=\"M 205.625197 75.231496 \n",
       "C 210.135738 75.231496 214.462146 73.439439 217.65158 70.250005 \n",
       "C 220.841014 67.060571 222.633071 62.734163 222.633071 58.223622 \n",
       "C 222.633071 53.713081 220.841014 49.386673 217.65158 46.197239 \n",
       "C 214.462146 43.007805 210.135738 41.215748 205.625197 41.215748 \n",
       "C 201.114656 41.215748 196.788248 43.007805 193.598814 46.197239 \n",
       "C 190.40938 49.386673 188.617323 53.713081 188.617323 58.223622 \n",
       "C 188.617323 62.734163 190.40938 67.060571 193.598814 70.250005 \n",
       "C 196.788248 73.439439 201.114656 75.231496 205.625197 75.231496 \n",
       "L 205.625197 75.231496 \n",
       "z\n",
       "\" style=\"fill:none;stroke:#000000;stroke-linejoin:miter;\"/>\n",
       "   </g>\n",
       "   <g id=\"matplotlib.axis_1\"/>\n",
       "   <g id=\"matplotlib.axis_2\"/>\n",
       "   <g id=\"text_1\">\n",
       "    <!-- Z -->\n",
       "    <defs>\n",
       "     <path d=\"M 5.609375 72.90625 \n",
       "L 62.890625 72.90625 \n",
       "L 62.890625 65.375 \n",
       "L 16.796875 8.296875 \n",
       "L 64.015625 8.296875 \n",
       "L 64.015625 0 \n",
       "L 4.5 0 \n",
       "L 4.5 7.515625 \n",
       "L 50.59375 64.59375 \n",
       "L 5.609375 64.59375 \n",
       "z\n",
       "\" id=\"BitstreamVeraSans-Roman-5a\"/>\n",
       "    </defs>\n",
       "    <g transform=\"translate(86.0743700787 63.1904970472)scale(0.18 -0.18)\">\n",
       "     <use xlink:href=\"#BitstreamVeraSans-Roman-5a\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"text_2\">\n",
       "    <!-- A -->\n",
       "    <defs>\n",
       "     <path d=\"M 34.1875 63.1875 \n",
       "L 20.796875 26.90625 \n",
       "L 47.609375 26.90625 \n",
       "z\n",
       "M 28.609375 72.90625 \n",
       "L 39.796875 72.90625 \n",
       "L 67.578125 0 \n",
       "L 57.328125 0 \n",
       "L 50.6875 18.703125 \n",
       "L 17.828125 18.703125 \n",
       "L 11.1875 0 \n",
       "L 0.78125 0 \n",
       "z\n",
       "\" id=\"BitstreamVeraSans-Roman-41\"/>\n",
       "    </defs>\n",
       "    <g transform=\"translate(142.775720965 63.1904970472)scale(0.18 -0.18)\">\n",
       "     <use xlink:href=\"#BitstreamVeraSans-Roman-41\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"text_3\">\n",
       "    <!-- X -->\n",
       "    <defs>\n",
       "     <path d=\"M 6.296875 72.90625 \n",
       "L 16.890625 72.90625 \n",
       "L 35.015625 45.796875 \n",
       "L 53.21875 72.90625 \n",
       "L 63.8125 72.90625 \n",
       "L 40.375 37.890625 \n",
       "L 65.375 0 \n",
       "L 54.78125 0 \n",
       "L 34.28125 31 \n",
       "L 13.625 0 \n",
       "L 2.984375 0 \n",
       "L 29 38.921875 \n",
       "z\n",
       "\" id=\"BitstreamVeraSans-Roman-58\"/>\n",
       "    </defs>\n",
       "    <g transform=\"translate(29.3814566929 40.5133316929)scale(0.18 -0.18)\">\n",
       "     <use xlink:href=\"#BitstreamVeraSans-Roman-58\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"text_4\">\n",
       "    <!-- Y -->\n",
       "    <defs>\n",
       "     <path d=\"M -0.203125 72.90625 \n",
       "L 10.40625 72.90625 \n",
       "L 30.609375 42.921875 \n",
       "L 50.6875 72.90625 \n",
       "L 61.28125 72.90625 \n",
       "L 35.5 34.71875 \n",
       "L 35.5 0 \n",
       "L 25.59375 0 \n",
       "L 25.59375 34.71875 \n",
       "z\n",
       "\" id=\"BitstreamVeraSans-Roman-59\"/>\n",
       "    </defs>\n",
       "    <g transform=\"translate(30.0494254429 85.8676624016)scale(0.18 -0.18)\">\n",
       "     <use xlink:href=\"#BitstreamVeraSans-Roman-59\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"text_5\">\n",
       "    <!-- C -->\n",
       "    <defs>\n",
       "     <path d=\"M 64.40625 67.28125 \n",
       "L 64.40625 56.890625 \n",
       "Q 59.421875 61.53125 53.78125 63.8125 \n",
       "Q 48.140625 66.109375 41.796875 66.109375 \n",
       "Q 29.296875 66.109375 22.65625 58.46875 \n",
       "Q 16.015625 50.828125 16.015625 36.375 \n",
       "Q 16.015625 21.96875 22.65625 14.328125 \n",
       "Q 29.296875 6.6875 41.796875 6.6875 \n",
       "Q 48.140625 6.6875 53.78125 8.984375 \n",
       "Q 59.421875 11.28125 64.40625 15.921875 \n",
       "L 64.40625 5.609375 \n",
       "Q 59.234375 2.09375 53.4375 0.328125 \n",
       "Q 47.65625 -1.421875 41.21875 -1.421875 \n",
       "Q 24.65625 -1.421875 15.125 8.703125 \n",
       "Q 5.609375 18.84375 5.609375 36.375 \n",
       "Q 5.609375 53.953125 15.125 64.078125 \n",
       "Q 24.65625 74.21875 41.21875 74.21875 \n",
       "Q 47.75 74.21875 53.53125 72.484375 \n",
       "Q 59.328125 70.75 64.40625 67.28125 \n",
       "\" id=\"BitstreamVeraSans-Roman-43\"/>\n",
       "    </defs>\n",
       "    <g transform=\"translate(256.033578986 63.1904970472)scale(0.18 -0.18)\">\n",
       "     <use xlink:href=\"#BitstreamVeraSans-Roman-43\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"text_6\">\n",
       "    <!-- B -->\n",
       "    <defs>\n",
       "     <path d=\"M 19.671875 34.8125 \n",
       "L 19.671875 8.109375 \n",
       "L 35.5 8.109375 \n",
       "Q 43.453125 8.109375 47.28125 11.40625 \n",
       "Q 51.125 14.703125 51.125 21.484375 \n",
       "Q 51.125 28.328125 47.28125 31.5625 \n",
       "Q 43.453125 34.8125 35.5 34.8125 \n",
       "z\n",
       "M 19.671875 64.796875 \n",
       "L 19.671875 42.828125 \n",
       "L 34.28125 42.828125 \n",
       "Q 41.5 42.828125 45.03125 45.53125 \n",
       "Q 48.578125 48.25 48.578125 53.8125 \n",
       "Q 48.578125 59.328125 45.03125 62.0625 \n",
       "Q 41.5 64.796875 34.28125 64.796875 \n",
       "z\n",
       "M 9.8125 72.90625 \n",
       "L 35.015625 72.90625 \n",
       "Q 46.296875 72.90625 52.390625 68.21875 \n",
       "Q 58.5 63.53125 58.5 54.890625 \n",
       "Q 58.5 48.1875 55.375 44.234375 \n",
       "Q 52.25 40.28125 46.1875 39.3125 \n",
       "Q 53.46875 37.75 57.5 32.78125 \n",
       "Q 61.53125 27.828125 61.53125 20.40625 \n",
       "Q 61.53125 10.640625 54.890625 5.3125 \n",
       "Q 48.25 0 35.984375 0 \n",
       "L 9.8125 0 \n",
       "z\n",
       "\" id=\"BitstreamVeraSans-Roman-42\"/>\n",
       "    </defs>\n",
       "    <g transform=\"translate(199.4503531 63.1904970472)scale(0.18 -0.18)\">\n",
       "     <use xlink:href=\"#BitstreamVeraSans-Roman-42\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "  </g>\n",
       " </g>\n",
       " <defs>\n",
       "  <clipPath id=\"pa6d68d3200\">\n",
       "   <rect height=\"113.385826772\" width=\"283.464566929\" x=\"7.2\" y=\"7.2\"/>\n",
       "  </clipPath>\n",
       " </defs>\n",
       "</svg>\n"
      ],
      "text/plain": [
       "<matplotlib.figure.Figure at 0x7f88e30e6ac8>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "pgm = daft.PGM([5, 2], origin=[-0.5, 0.5])\n",
    "add_node(pgm, 'X', 'X', 0, 2)\n",
    "add_node(pgm, 'Y', 'Y', 0, 1.2)\n",
    "add_node(pgm, 'Z', 'Z', 1, 1.6)\n",
    "add_node(pgm, 'A', 'A', 2, 1.6)\n",
    "add_node(pgm, 'B', 'B', 3, 1.6)\n",
    "add_node(pgm, 'C', 'C', 4, 1.6)\n",
    "add_edges(pgm, [\n",
    "        ('X', 'Z'),\n",
    "        ('Y', 'Z'),\n",
    "        ('Z', 'A'),\n",
    "        ('A', 'B'),\n",
    "        ('B', 'C')\n",
    "    ])\n",
    "pgm.render()\n",
    "save('bayes_net_triple')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.5.0"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}
